Microsoft Visual Basic training - Create a full FTP Client Windows Application

How to upload and download files using FTP and Visual Basic 6.0


vby6 home

BLOBs vb6

Creating a Windows FTP application using Visual Basic 6.0

Introduction

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.

Active mode

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.

Passive mode

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.

FTP Commands

RFC 959
CDUP
Change to Parent Directory
RMD
Remove Directory
SMNT
Structure Mount
MKD
Make Directory
STOU
Store Unique
PWD
Print Directory
SYST
System

End-Of-Line

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.

File

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

FTP CommandDescription
CD dir
Changes the current directory to the specified directory on the remote computer
CDUP
Changes the current directory to the parent directory on the remote computer
CLOSE
Closes the connection to the remote computer
DELETE file
Deletes the specified file on the remote computer
DIR [dir]
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
LS [dir]
Same as DIR
MKDIR 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
PWD
Returns the current directory from the remote computer (use GetChunk to get the information)
QUIT
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
RMDIR dir
Deletes the specified directory
SEND file1 file2
Same as PUT
SIZE dir
Returns the size of the specified directory (use GetChunk to get the information)
WARNING: Security, security, security: Just because a command is listed here does not mean it can be used. Your user name and password will determine your level of access to the files on the server, as well as which commands you will be able to execute. (Source : Microsoft MSDN)

FTP Examples

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 :

Site
Number of files
Total file size
3,544,263
1.69 TB
3,527,635
1.67 TB
3,255,949
924.57 GB
2,775,630
2.33 TB
2,570,430
886.73 GB
2,565,731
1.10 TB
2,492,429
848.58 GB
2,471,007
894.94 GB
2,458,485
713.28 GB
2,351,994
924.37 GB
2,339,290
1000.26 GB
2,291,942
705.39 GB
2,267,934
645.16 GB
2,192,106
943.63 GB
2,112,017
748.59 GB
2,081,328
685.59 GB
2,019,592
1.03 TB
1,966,283
502.80 GB
1,963,407
474.40 GB
1,859,494
514.56 GB

* 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) :

FileZillaFree FTP Client
CyberDuckFree FTP Client
WS_FTPFree FTP Client
Core FTPFree FTP Client

Project Design

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.

Visual Basic 6.0 FTP Client Source Code

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 :

  1. Connect to FTP remote server.
  2. Retrieving main/sub directories from FTP remote server.
  3. Retrieving files from FTP remote server.
  4. Uploading file to FTP remote server.
  5. Downloading file from FTP remote server.
  6. Make new directory (folder) at FTP remote server.
  7. 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 :

  1. The Spaces problem while downloading and uploading files.
  2. Error message "Still executing last request" number 35764.
  3. Error message "File exists"
  4. Application Hangs up after ending it.
  5. Using TreeView control to list all the Directories on the FTP remote server.
  6. Using ListBox control to list all files on the FTP remote server related to above folder.

FSO Library

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

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 :

 Downloan the source code + FTP.exe from a direct link from Mediafire.com

Labels :

Visual Basic 6.0 File Transfer Protocol, Visual Basic 6.0 FTP, visual basic program tutorials, visual basic programming tutorial, Visual Basic, learning visual basic, visual basic training, visual basic for dummies, learn visual basic 2010, visual basic classes, visual basic coding, learn visual basic programming, learn visual basic online, visual basic programmer, visual basic help, help with visual basic, visual basic programming help, visual basic 2010 help, microsoft visual basic help, microsoft visual basic 6.0 help, vb programmers, Visual Basic 6.0, visual basic 6.0 software, visual basic 6.0 training, learn visual basic 6.0, ms visual basic 6.0, visual basic 6.0 pro, visual basic 6.0 learning edition, software of visual basic 6.0, how to learn visual basic 6.0, learning visual basic 6.0, visual basic 6.0 price

About Us | Contact Us | ©2013 evry1falls

Free Web Hosting