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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to download automatically a file from URL 1

Status
Not open for further replies.

pit75

Programmer
Jun 3, 2003
15
US
Hi,
I've an application in which I need to download, every time it starts (on form_laod), a file from a url.
I know the name of the file, always the same; i need to know what kind of controls and statements I should use to make this,...have you any tips?

Thank you


 
I've noticed that there are several question like this in Vb forums, and no-one with a resolutive reply. Maybe too simple question.

Otherwise, for future threads like this , the MSDN provides this code:

'this if you have a firewall
With Inet1
.URL = "your url"
.UserName = "username"
.Password = "password"
.Execute , "GET "

.Execute , "CLOSE" ' Close the connection.
End With

Dim intFile As Integer ' FreeFile variable
intFile = FreeFile()

Open "path & name of file destination" For Output As #intFile
Write #intFile, Inet1.OpenURL("your URL")
Close #intFile

End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim vtData As Variant ' Data variable.
Select Case State
' ... Other cases not shown.
Case icResponseCompleted ' 12
' Open a file to write to.
Open txtOperation For Binary Access _
Write As #intFile

' Get the first chunk. NOTE: specify a Byte
' array (icByteArray) to retrieve a binary file.
vtData = Inet1.GetChunk(1024, icString)

Do While LenB(vtData) > 0
Put #intFile, , vtData
' Get next chunk.
vtData = Inet1.GetChunk(1024, icString)
Loop
Put #intFile, , vtData
Close #intFile
End Select
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top