Main Page / Browse Categories / Howto's & Guides / FTP / Understanding FTP
Understanding FTP
FTP is an abbreviation for File Transfer Protocol. It is a standard for moving files from one computer to another over a network. Files are moved in either ASCII (text) or BINARY form.

Files such as Simple text, HTML, Postscript files should be moved in ASCII (text) form. Word processor, spreadsheet, images, executables, and other files should be moved in BINARY form.

 

A Simply FTP Session

The client program connects to an FTP sever on the internet. Once connected, the FTP server sends a welcome message to the client over the open socket (network) connection.

Server: 220 Sample FTP server ready. Please give user-name
Client: USER anonymous
Server: 331 User name OK. Please give your email address as password
Client: PASS joe@nowhere.comm
Server: 230 User logged in

As you can see, the client and server are communicating in plain text. The digits in the server replies are 'reply-codes' defined by the FTP protocol. The uppercase words in the beginning of the client commands, are command verbs that also are defined by the RFC. The protocol is designed in a way that makes it easy for machines and humans to understand the dialog. In most cases, the client program doesn't have to interoperate the text after the reply code.

Now, the user wants to see the available files and directories, and issues a DIR command in the client program.

Client: TYPE A
Server: 200 Type set to A
Client: PASV
Server: 227 Entering passive mode (193,91,161,12,28,46)
Client: LIST
Server: 150 Opening ASCII mode data connection for /bin/ls
Server: 226 Transfer complete

The TYPE command tells the server to send the directory / file listing as plain ASCII, where each line is separated by a CRLF sequence. The PASV command tells the server to prepare for a new socket connection by creating a new socket and then listening for a connection from the client. Now, as you see, things are getting a little more complicated. The server reply includes a IP address and a port number, encoded as 6 different number values, separated by commas. The client must find and understand this address in order to receive the listing.

The LIST command tells the server to give a directory / file listing. Now the server replies with two reply lines... What's happening is that the first line tells the client that the listing is ready and that the client can go on and make a new connection to the server. The client connects to the IP address given by the PASV reply and receives data until there is no more data to get. Then it closes the temporary data connection and switches back to the control connection to get the second reply line, which tells if the server transferred the whole listing.

In order to receive a directory listing, the client and server use two socket connections, one for the control flow (server sends commands, the server replies in plain text) and one for the data connection (which is continuous and goes in one direction only). Every time a directory-listing is sent, the server and client will use another new (temporary) socket connection for the transfer.

The user finds an interesting file, and gives the FTP client the command to get it.

Client: TYPE I
Server: 200 Type set to I
Client: PASV
Server: 227 Entering passive mode (193,91,161,12,28,46)
Client: RETR test.zip
Server: 150 Opening BINARY mode data connection for test.zip
Server: 226 Transfer complete

As you see, the server and client use the exact same method to get a file, as they do to get a directory listing. The only change is that the RETR command is used in stead of the LIST command. In this case, the file was a .zip archive. Since such files can't be translated to text-files (at least not in a safe manner), the FTP client switched to binary mode (TYPE I). File and directory listings can be transferred in both binary and text-mode. Since different operating systems use different means to separate lines in text-files, it is generally a good idea to let the FTP server and FTP client do the conversion. Both know the rules for a ASCII (text) transfer and the client always knows the rules for the local storage of text-files.



User Comments
Understanding FTP
Add Comment
There are no user comments for this topic.
Add Comment
Additional Info
General Information
Article No. 189
Created: 04:10 AM 12.26.03
Author: HPU Support

Attachments
No attachments.

Did this help you?
Yes No

Statistics
Yes562 (49%) Voted Yes585 (51%) Voted NoNo

Other Options
Print Article
Email Article

Related Articles
There are currently no related articles.