Creating a Windows FTP application using Visual Basic 6.0
What is FTP ?
FTP stands for File Transfer Protocol and is a way or method to transfer files from one host to another host over TCP-based network like Internet. You can work on a FTP server as a client using an authentication process [Username& Password] or anonymously if the server is set to allow it.
The original method to connect to a FTP server from a client's computer by establishing a TCP connection by the client and sending the IP address of the client's computer and the port number then wait for the response from the Server to start the connection process.
When the client's computer is behind a firewall or can not receive TCP connections from the FTP server. In this case the client sends a PASV Command to the FTP server, then the FTP server sends back the IP Address and the port number to the client's computer, which the client's computer uses to initiate the connection to the FTP Server.
|Change to Parent Directory|
The end of line sequence defines the separation of lines. The sequence is Carriage-Return followed by a Line-Feed which is defined in Visual Basic 6.0 as VBCRLF.
Computer Data including programs uniquely identified by its full path, in Visual Basic 6.0 you can use the full-path to a file explicitly (I.e: C:\Dir1\Dir2\filename.ext) or using the built-in functions in Visual Basic 6.0 to get the full-path of a file (I.e: To get the full path of a file stored in the main project directory, use (PathToFile=App.Path & "/filename.ext") or the FSO File System Objects Library.
Issuing FTP commands from Visual Basic 6.0 :
FTP Commands for the Internet Transfer Control
Changes the current directory to the specified directory on the remote computer
Changes the current directory to the parent directory on the remote computer
Closes the connection to the remote computer
Deletes the specified file on the remote computer
Returns the list of files from the specified directory (use GetChunk to get the information)
|GET file1 file2|
Retrieves the specified file (file1) from the remote computer and saves it as the specified file (file2) on the local computer
Same as DIR
Creates the specified directory on the remote computer
|PUT file1 file2|
Sends the specified file (file1) from the local computer and saves it as the specified file (file2) on the remote computer
Returns the current directory from the remote computer (use GetChunk to get the information)
Terminates the current userís session on the remote computer
|RECV file1 file2|
Same as GET
|RENAME file1 file2|
Changes the name of the specified file (file1) to the specified name (file2) on the remote computer
Deletes the specified directory
|SEND file1 file2|
Same as PUT
Returns the size of the specified directory (use GetChunk to get the information)
FTP Servers and FTP web hosting
We will create FTP desktop application .... Why ?
Because we want to manage files stored on an FTP Server from our Desktop application without login into the FTP Server and do it from there, also there are several FTP Servers that don't use managing files directly from their location, another reason is to be able to see the transferring process from your local directory to the FTP Server directories.
Some examples of the FTP Servers that you can login *anonymously :
Number of files
Total file size
* If none of the above FTP didn't open, then it must have been closed or is now down for any reason.
You can also sign-up for FTP secure web-hosting that provides you with a user-name and a password for your own usage. Here is a list of a secure (Personal use) free web-hosting with FTP Server :
|freewebhostingarea.com/||Free web hosting plan with FTP Server|
|zymic.com/free-web-hosting/||Free web hosting plan with FTP Server|
|0fees.net/||Free web hosting plan with FTP Server|
|nofeehost.com/||Free web hosting plan with FTP Server|
|awardspace.com/||Free web hosting plan with FTP Server|
If you are into web design then you need to transfer your files all the time from the server and into the server, and if you are a programmer and a client requires FTP file manager then this is your chance to qualify yourself .
Here is a list of FTP desktop applications or (FTP Clients) :
|FileZilla||Free FTP Client|
|CyberDuck||Free FTP Client|
|WS_FTP||Free FTP Client|
|Core FTP||Free FTP Client|
What is the project design ?
The design has to be user-friendly because the FTP technology is not well-known techonology as the Http:// or Https:// though it is easier to work with and to use.
You will find the Download link for both of the FTP Client using Microsoft Visual Basic 6.0 (My Custom FTP) and the FTP source code hosted free on Mediafire.com direct download link at the end of this page.
The Visual Basic 6.0 project has only one form, and the most important control on it, is the MS-Inet control (Microsoft Internet Transfer Control v. SP6) because it's the control that is responsible for doing the transferring job from and into the FTP Server.
In this project we shall discuss :
- Connect to FTP remote server.
- Retrieving main/sub directories from FTP remote server.
- Retrieving files from FTP remote server.
- Uploading file to FTP remote server.
- Downloading file from FTP remote server.
- Make new directory (folder) at FTP remote server.
- Rename & Delete file from FTP remote server.
In this project we won't be using API calls (i.e. INET API) but we will cover these issues :
- The Spaces problem while downloading and uploading files.
- Error message "Still executing last request" number 35764.
- Error message "File exists"
- Application Hangs up after ending it.
- Using TreeView control to list all the Directories on the FTP remote server.
- Using ListBox control to list all files on the FTP remote server related to above folder.
I used the (FSO Library) File System Object and that is why you will find the relevant DLL file (scrrun.dll) included too in the source code folder, we used it to make sure that there is no duplications problems happen while executing codes to FTP server, also it's a way to get the Path & FileName without spaces because it's a big problem when working with Internet elements like Inet FTP that it's not allowed to use spaces in your file names or paths.
Source Code Highlights
We will not use any Windows APIs, and this is the different thing about this tutorial.
The Inet Control has only one beautiful and powerful Sub called (StateChanged(ByVal State As Integer)), almost the whole transferring process gets done within this Sub. For example :
To connect to FTP Server using VB 6.0 Inet control, use this code :
This code will enable you to create a new directory on the FTP Server :