Today I am showing you how to construct an FTP program. The File Transfer Protocol is a system for transferring files between two computers over the Internet where one of the computers is normally known as server and the other one as the client. The FTP program is very useful for website management as the webmaster can update the web pages by uploading the local files to the web server easily and normally at a much faster speed than the web browser. For normal PC users, the FTP program can also be used to download files from many FTP sites that offer a lot of useful stuffs such as free software, free games, product information, applications, tools, utilities, drivers, fixes and etc.
The FTP program usually comprises an interface that shows the directories of the local computer and the remote server. Files can normally be transferred just by clicking the relevant arrows. To log into the FTP site, we normally have to key in the user name and the password; however, for public domains, we just need to type the word anonymous as the user name and you can leave out the password. The FTP host name takes the form ftp.servername.com, for example, the Microsoft FTP site’s host name is ftp.microsoft.com while the Netscape FTP site is ftp.netscape.com.
The FTP program usually provides a set of commands such as ChgDir (changing directory), MkDir (Changing directory), Rename (renaming a file), view (to view a file), delete (to delete a file) and etc.
Visual Basic allows you to build a fully functional FTP program which may be just as good as the commercial FTP programs. The engine behind it is the Microsoft Internet Transfer Control 6.0 in which you need to insert your form before you can create the FTP program. The name of the Microsoft Internet Transfer Control 6.0.is Inet and if you only put in one control, its name will be Inet1.
Inet1 comprises three important properties namely Inet1.URL that is used to identify the FTP hostname, inet1.UserName that is used to accept the username and the Inet1.Password that is used to accept the user’s passwords. The statements for the program to read the hostname of the server, the username and the password entered into Textbox1, Textbox2 and Textbox3 by the user are shown below:
After the user entered the above information, the program will attempt to connect to the server using the following command, where Execute is the method and DIR is the FTP command that will read the list of files from the specified directory of the remote computer and you need to use the getChunk method to actually retrieve the directory’s information.
After connecting to the server, you can choose the file from the remote computer to download by using the statement below:
Inet1.Execute, , "get" & remotefile & localfile
where remotefile is the file of the remote site and localfile is the file of the local system. However, very often you need to provide the full path of the local file, which you can do that by modifying the above syntax to the following syntax:
Inet1.Execute , , "get" & remotefile & localpath & remotefile
The above statements will ensure that the remote file will be downloaded to the location specified by the localpath and the file downloaded will assume the same name as the remote file. For example, the remote file is readme.txt and the localpath is C:\temp , so the downloaded file will be saved in C:\temp\readme.txt.