FTPing a file from/to a VB application

There is a simple way of doing FTP using Internet Transfer Control. You need to include this control in your project before using this control.

To down load or upload a file, you need to know the URL of the remote server, user name and password to access the server. These values to be set before executing any command thru this control.

Lets assume there is an Internet transfer control placed in a name Inet1 and we want to download a file called 'test1.txt' from a server called 'ftp.xyz.com'. Following statements will do that.

'Initialize the Inet control
Inet1.URL = "FTP://ftp.xyz.com"
Inet1.Username = "abc"
Inet1.Password = "abc"

'Invoke execute method to down load a file
Inet1.Execute "","GET test1.txt C:\Temp\test1.txt"

On executing the above statement, the system will download the file from the remote server and copies in to temp directory of the local drive.

The same statement can be used as below if URL property is not set already.
Inet1.Execute "FTP://ftp.xyz.com","GET test1.txt C:\Temp\test1.txt"

When executing the above statement, if username and password properties are null or "" then 'anonymous' will be sent as user name and password will be user's email address.

For instance to upload a file 'test1.txt' to the remote server the following statement can be used.
Inet1.Execute "","PUT test1.txt test1.txt"

Note: Internet transfer control executes FTP commands asynchronously, so control returns to the next statement immediately, so you may need to check 'StillExecuting' prperty to find out if it has finished the previous command.