Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Internet Transfer Control Download File

Status
Not open for further replies.

Brent113

Programmer
Aug 13, 2003
67
0
0
US
I am trying to download a binary file using the internet transfer control using the .getchunk(...) so I can show progress. But it doesn't work. I have gone to a lot of sites on google but I can't seem to make it work. What doesn't work in particular is the Inet1_StateChanged(ByVal State As Integer) doesn't ever run, though its supposed to. I can't get the .Execute(...) to work though I can use the .OpenURL relatively successfully. I have so far:

' all undeclared variables are public
' backup_new.tmp is about 130 KB

Public Sub DownloadProgram()
Dim ByteArray() As Byte
FileName = "backup_new.tmp"
Inet1.URL = "[some arbitrary website]"
Inet1.Execute , "GET"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer) 'This doesn't run
On Error Resume Next
Dim sngProgerssValue As Single
Dim vtData As Variant

Select Case State
Case icResponseCompleted ' 12
Dim bDone As Boolean: bDone = False
Dim tempArray() As Byte

Max = Inet1.GetHeader("Content-length")

If Len(FileName) Then
Open FileName For Binary Access Write As #1
' Get first chunk.
vtData = Inet1.GetChunk(1024, icByteArray)
DoEvents

If Len(vtData) = 0 Then
bDone = True
End If

Do While Not bDone
tempArray = vtData
Put #1, , tempArray

' Get next chunk.
vtData = Inet1.GetChunk(1024, icByteArray)
DoEvents

If Len(vtData) = 0 Then
bDone = True
End If
Loop
Close #1
End If
' End Case
End Select
End Sub

____________________________________________________________________________
There are only 10 types of people in the world. Those that know binary and those that don't

Brent
 
Try this

*******************************
Dim ByteArray() as Byte
ByteArray() = Inet1.OpenURL("ftp://ftp.test.com/test.tmp" , icByteArray)

Then you can save the download file to disk as follow:

Open "c:\test.tmp" for Binary as #1
Put #1,, ByteArray()
Clase #1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top