Internet File Transfer From Website
This is a module for easily adding the ability to transfer a file from a webserver to a hard drive. Good for a "live update" type of functionality or for downloading banners to your program. By Erick Jones, http://www.webdataconsultants.com
Original Author: webdataconsultants
Inputs
You must provide a URL of the source file and a filename for the downloaded file name
Assumptions
First of all, this is a module. You'll have to add the module to your project. You also have to add a Microsoft Internet Transfer Control (and a Label1 Control if you are using the example below) to your form.
EXAMPLE USAGE:
Label1.Caption = "Getting File..."
TransferFile = Xfer(Inet1, "http://www.webdata.addr.com/index.html", App.Path + "index.html")
Label1.Caption = InetStatus
Returns
InetStatus returns the status of the file transfer or an error if the transfer is unsuccessful.
API Declarations
Global TransferFile As Boolean
Global b() As Byte
Global InetStatus As String
Code
'####################################
'# Created 2002 Webdata Consultants #
'# You are free to use this module #
'# as long as you keep this header #
'# intact. #
'# www.webdataconsultants.com #
'####################################
'
'First of all, to use this module you have
'add a Microsoft Internet Transfer Control
'and a Label1 Control to your form.
'
'EXAMPLE USAGE:
'Label1.Caption = "Getting File..."
'TransferFile = Xfer(Inet1, "http://www.webdata.addr.com/index.html", App.Path + "index.html")
'Label1.Caption = InetStatus
Global TransferFile As Boolean
Global b() As Byte
Global InetStatus As String
Public Function Xfer(Inet1 As Inet, strURL As String, InputFile As String) As Boolean
On Error GoTo ErrorHandle
Inet1.AccessType = icUseDefault
Inet1.RequestTimeout = 10 'Higher number increases request timeout
b() = Inet1.OpenURL(strURL, icByteArray)
Open InputFile For Binary Access _
Write As #1
Put #1, , b()
Close #1
InetStatus = "Done"
Exit Function
ErrorHandle:
Select Case Err.Number
Case 75
InetStatus = "Destination file is read-only."
Case 35761
InetStatus = "Request timed out. Please check your internet connection or try again later."
Case Else
InetStatus = "Error: " & Err.Number
End Select
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.