Microsoft ships a redistributable msinet.ocx
with a number of products including Visual Basic 5.0, 6.0, Office 2000
Developer, Visual FoxPro 6.0, Visual C++ 5.0, 6.0. This file hosts Microsoft
Internet Transfer Control which implements a number of protocols including
HTTP and FTP. You need to know the commands that initiate the operations.
The code snippet given below shows how to use
Microsoft Internet Transfer Control to download a file from a machine. To use
the code, make sure that you add a reference to Microsoft Internet Transfer
Control. To add a reference to it
- Select Tools | References....
- Select Microsoft Internet Transfer Control
from the available references.
- If it is not available, click the Browse...
button. You will be presented with the Add Reference dialog box.
- Locate and select MSINET.OCX. This file is usually present in
the System folder.
- Click Open to dismiss the Add Reference dialog box.
- Click OK.
Function
DownloadFile(ByVal HostName
As String, _
ByVal UserName
As String, _
ByVal Password
As String, _
ByVal RemoteFileName
As String, _
ByVal LocalFileName
As String) As Boolean
Dim FTP
As Inet
Set FTP =
New Inet
With FTP
.Protocol = icFTP
.RemoteHost = HostName
.UserName = UserName
.Password = Password
.Execute .URL, "Get " +
RemoteFileName + " " + LocalFileName
Do While .StillExecuting
DoEvents
Loop
DownloadFile = (.ResponseCode
= 0)
End With
Set FTP =
Nothing
End Function
Some points to keep in mind
- The function returns True if the
operation succeeds otherwise it returns False.
- If the specified file (LocalFileName) is
already present on the machine, the function will fail. It does not
overwrite the existing file.
See Also
Upload File Using FTP
|
|