File Transfer Protocol
File Transfer Protocol
File Transfer Protocol (FTP) is the standard mechanism provided by TCP/IP for copying a file from one host to another. FTP differs from other client server applications in that it establishes two connections between hosts. One connection is used for data transfer, the other for control information. FTP uses the services of TCP. It needs two TCP connections. The well-known port 21 is used for the control connection and the well-known port 20 for the data connection.
Connections:
The two FTP connections , control and data, use different strategies and different port numbers.
Control Connection
There are two steps in control connection: 1. The server issues a passive open on the well known port 21 and waits for a client. 2. The client uses an ephemeral port and issues an active open The connection remains open during the entire process. The service type, used by the IP protocol, is minimize delay because this is an interactive connection between a user and a server. The user types commands and expects to receive responses without significant delay. Figure shows the initial connection between the server and the client.
Data Connection
The data connection uses the well known port 20 at the server site. Steps to create a data connection: 1.The client not the server issues a passive open using an ephemeral port. 2.The client sends this port number to the server using the PORT command.
3.The server receives the port number and issues an active open using the well known port 20 and the received ephemeral port number.
The steps for creating the initial data connection are shown in the figure.
Communication
FTP has two different approaches, one for control connection and one for the data connection.
Concept of NVT
Via a universal interface called the Network Virtual Terminal (NVT) character set, the client translates characters (data or commands) that come from the local terminal into
NVT form and delivers them to the network. The server translates data and commands from NVT form into the form acceptable by the remote computer.
Data Structure
Transferring of a file can be done using one of the following implementations about the structure of the data 1. File Structure: the file has no structure. It has continuous stream of bytes. 2. Record Structure: The file is divided into text. This can be used only with text files. 3. Page Structure: The file is divided into pages with each page having a page number and a page header.
Transmission Mode
One of the following three transmission mode can be used to transfer a file: 1. Stream mode: Data are delivered from FTP to TCP as a continuous stream of bytes. 2. Block mode: Data can be delivered from FTP to TCP in blocks. 3. Compressed mode: if the file is big data can be compressed.
Command processing
FTP uses the control connection to establish a communication between the client control process and the server control process. During this connection commands are sent from the client to the server and the responses are sent from the server to the client.
Command processing
Commands
Commands which are sent from the FTP client control process are in the form of ASCII uppercase which may or may not be followed by an argument. Commands can be divided into six groups as follows:
Access commands
These commands let the user access the remote system. Common commands in this group are:
Miscellaneous commands
These commands deliver information to the FTP user at the client side.
Responses
Every FTP command generates at least one response. A response has two parts: a three-digit number followed by text. The numeric part defines the code; the text part defines needed parameters or extra applications. We represent the three digits as xyz. Meaning of each digit is described as follows: First digit: The first digit defines the status of the command. One of five digits can be used in this position: 1yz(positive preliminary reply): The action has started. The server will send another reply before accepting another command. 2yz(positive completion reply): The action has completed. The server will accept another command. 3yz (positive intermediate reply): The command has been accepted, but further information is needed. 4yz(transient negative completion reply): The action did not take place, but the error is temporary. The same command can be sent later. 5yz(permanent negative completion reply): The command was not accepted and should be retried again. Second digit: The second digit also defines the status of the command. One of six digits can be used in this position: x0z(syntax) x1z(information) x2z(connections) x3z(authentication and accounting) x4z(unspecified) x5z(file system)
File transfer
File transfer occurs over the data connection under the control of the commands sent over the control connection. A file transfer FTP means: -A file is to be transferred from the server to the client called as retrieving of file and is done under the supervision of the RETR command. -A file is to be transferred from the client to the server called as storing of file and is done under the supervision of the STOR command. -A list of ff directory or file names is to be sent from the server to the client done under the supervision of the LIST command.
6. The client issues a passive open on an ephemeral port for the data connection and sends the PORT command (over the control connection) to give this port number to the server. 7. The server does not open the connection at this time, but it prepares itself for issuing an active open on the data connection between port 20 (server side) and the ephemeral port received from the client. It sends response 150 (data connection will open shortly). 8. The client sends the LIST message. 9. Now the server responds with 125 and opens the data connection. 10. The server then sends the list of the files or directories (as a file) on the data connection. When the whole list (file) is sent, the server responds with 226 (closing data connection) over the control connection. 11. The client now has two choices. It can use the QUIT command to request the closing of the control connection or it can send another command to start another activity (and eventually open another data connection). In our example, the client sends a QUIT command. 12. After receiving the QUIT command, the server responds with 221 (service closing) and then closes the control connection.
$ ftp voyager.deanza.fhda.edu
Connected to voyager.deanza.fhda.edu. 220 (vsFTPd 1.2.1) 530 Please login with USER and PASS. Name (voyager.deanza.fhda.edu:forouzan): forouzan 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls reports
227 Entering Passive Mode (153,18,17,11,238,169) 150 Here comes the directory listing. drwxr-xr-x 2 3027 411 4096 Sep 24 2002 business drwxr-xr-x 2 3027 411 4096 Sep 24 2002 personal drwxr-xr-x 2 3027 411 4096 Sep 24 2002 school 226 Directory send OK. ftp> quit 221 Goodbye.
Anonymous FTP
We assume that some public data are available at internic.net. $ ftp internic.net Connected to internic.net 220 Server ready Name: anonymous 331 Guest login OK, send guest as password Password: guest ftp > pwd 257 / is current directory ftp>ls 200 OK 150 Opening ASCII mode bin ... ftp > close 221 Goodbye ftp > quit