paulstamp
asked on
Download a text file using HTTP
Can anyone give me an EXAMPLE of how to download a text file from a server onto the local machine without any user interaction (ie no prompts to run from current location or save).
Ie the answer I am looking for is a complete version of the following
Public Function GetFile(byval sURL as string, byval sFileName as string) as Boolean
'Download and store file at sURL as sFilename
'Return True/False based on success of operation
End Function
I have seen a very similar question posted here before but the accepted answer wasnt a complete solution and I cant get it to work.
Anybody able to provide me with a complete example in the format above ?
Cheers
Ie the answer I am looking for is a complete version of the following
Public Function GetFile(byval sURL as string, byval sFileName as string) as Boolean
'Download and store file at sURL as sFilename
'Return True/False based on success of operation
End Function
I have seen a very similar question posted here before but the accepted answer wasnt a complete solution and I cant get it to work.
Anybody able to provide me with a complete example in the format above ?
Cheers
are you partial against using the inet control?
ASKER
Nope... thats fine.
well you can stick an inet control on your form and try this:
Dim b() As Byte
Dim intCount As Integer
Dim strData As String
Inet1.Cancel ' Stops any current operations
b() = Inet1.OpenURL("http://www.vbsquare.com/index.html", icByteArray)
For intCount = 0 To UBound(b) - 1
strData = strData & Chr(b(intCount))
Next intCount
Open "myfile.txt" For Binary Access Write As #1
Put #1, , b()
Close #1
Dim b() As Byte
Dim intCount As Integer
Dim strData As String
Inet1.Cancel ' Stops any current operations
b() = Inet1.OpenURL("http://www.vbsquare.com/index.html", icByteArray)
For intCount = 0 To UBound(b) - 1
strData = strData & Chr(b(intCount))
Next intCount
Open "myfile.txt" For Binary Access Write As #1
Put #1, , b()
Close #1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi
What do you meen "Text File?" Page?
Add Internet Transfer Control(Inet1) at your form
Private Function GetPage(sURL As String, sFile As String) As Boolean
Dim nFile As Integer
GetPage = True
On Error GoTo ERROR_GetPage
Dim b() As Byte
Inet1.Cancel
Inet1.Protocol = icHTTP
Inet1.URL = sURL
b() = Inet1.OpenURL(, icByteArray)
nFile = FreeFile
Open sFile For Binary Access Write As nFile
Put nFile, , b()
Close nFile
EXIT_GetPage:
Exit Function
ERROR_GetPage:
Select Case MsgBox("Error " & Err.Number & ": " & Err.Description & " at line: " & Erl, vbAbortRetryIgnore + vbCritical, "Error")
Case vbAbort
Screen.MousePointer = vbDefault
GetPage = False
Resume EXIT_GetPage:
Case vbRetry
Resume
Case vbIgnore
GetPage = False
Resume Next
End Select
Resume EXIT_GetPage
End Function
What do you meen "Text File?" Page?
Add Internet Transfer Control(Inet1) at your form
Private Function GetPage(sURL As String, sFile As String) As Boolean
Dim nFile As Integer
GetPage = True
On Error GoTo ERROR_GetPage
Dim b() As Byte
Inet1.Cancel
Inet1.Protocol = icHTTP
Inet1.URL = sURL
b() = Inet1.OpenURL(, icByteArray)
nFile = FreeFile
Open sFile For Binary Access Write As nFile
Put nFile, , b()
Close nFile
EXIT_GetPage:
Exit Function
ERROR_GetPage:
Select Case MsgBox("Error " & Err.Number & ": " & Err.Description & " at line: " & Erl, vbAbortRetryIgnore + vbCritical, "Error")
Case vbAbort
Screen.MousePointer = vbDefault
GetPage = False
Resume EXIT_GetPage:
Case vbRetry
Resume
Case vbIgnore
GetPage = False
Resume Next
End Select
Resume EXIT_GetPage
End Function
Hi
AzraSound:Sorry, look at time when i posted message - I didn't see your comments.
Cheers
AzraSound:Sorry, look at time when i posted message - I didn't see your comments.
Cheers
Not a problem....the more the merrier for those who need answers =)
ASKER
Thanks AzraSound... thats pretty much what I needed. Only two minor problems :
a) Unfortunately it puts quotes around the data in the file but thats not a big issue.
b) It seems to be cacheing the file somewhere : The situation is I'm writing a vb front end to a web-based system (I'm writing both sides of the equation), and when I modify the text file on my web site I still seem to be getting the file I first downloaded.
Any ideas (not to worry if you havent - you have already answered my real question).
Cheers
a) Unfortunately it puts quotes around the data in the file but thats not a big issue.
b) It seems to be cacheing the file somewhere : The situation is I'm writing a vb front end to a web-based system (I'm writing both sides of the equation), and when I modify the text file on my web site I still seem to be getting the file I first downloaded.
Any ideas (not to worry if you havent - you have already answered my real question).
Cheers
ASKER
Actually.. scrub the last point - I've found out why its downloading an old version - got two different versions of the web site and I'm looking at wrong one !