FTP - 100549
FTP - 100549
• The control connection remains connected during the entire interactive FTP session.
• The data connection is opened and then closed for each file transferred.
• While the control connection is open, the data connection can be opened and closed
multiple times if several files are transferred.
Connections
• The two FTP connections : control and data, use different strategies and different port
numbers.
Control Connection
• There are two steps:
1. The server issues a passive open on the well-known port 21 and waits for a client.
2. The client uses an temporary 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 (human) and a server.
• The user types commands and expects to receive responses without significant delay.
Data Connection
• The data connection uses the well-known port 20 at the server site.
• The following steps shows how FTP creates a data connection:
1. The client, not the server, issues a passive open using an ephemeral port. This must be done
by the client because it is the client that issues the commands for transferring files.
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 wellknown port 20
and the received ephemeral port number.
• The steps for creating the initial data connection are shown in figure.
Communication
• FTP has two different approaches, one for the control connection and one for the data
connection.
Communication over Control Connection
• It uses the 7 bit NVT ASCII character set.
• FTP can transfer one of the following file types across the data connection:
ASCII file. This is the default format for transferring text files. Each character is encoded
using NVT ASCII. The sender transforms the file from its own representation into NVT
ASCII characters and the receiver transforms the NVT ASCII characters to its own
representation.
EBCDIC file. If one or both ends of the connection use EBCDIC encoding, the file can be
transferred using EBCDIC encoding.
Image file. This is the default format for transferring binary files. The file is sent as
continuous streams of bits without any interpretation or encoding. This is mostly used to
transfer binary files such as compiled programs.
Data Structure
• FTP can transfer a file across the data connection using one of the following
interpretations about the structure of the data:
File structure (default). The file has no structure. It is a continuous stream of bytes.
Record structure. The file is divided into records. This can be used only with text files.
Page structure. The file is divided into pages, with each page having a page number and a
page header. The pages can be stored and accessed randomly or sequentially.
Transmission Mode
• FTP can transfer a file across the data connection using one of the following three
transmission modes:
Stream mode.
• Data are delivered from FTP to TCP as a continuous stream of bytes. TCP is responsible for
chopping data into segments of appropriate size.
• If the data is in file structure, no end-of-file is needed. End-of-file in this case is the closing
of the data connection by the sender.
• If the data is in record structure, each record will have a 1-byte end-of-record (EOR)
character and the end of the file will have a 1-byte end-of-file (EOF) character.
Block mode.
• The next two bytes define the size of the block in bytes.
Compressed mode.
• In this method, consecutive appearances of a data unit are replaced by one occurrence and the
number of repetitions.
• In a text file, this is usually spaces (blanks).
3. The server responds with 331 (user name is OK, password is required).
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.
Command Processing
• FTP uses the control connection to establish a communication between the client control
process and the server control process. During this communication, the commands are
sent from the client to the server and the responses are sent from the server to the client
Commands
• Access commands. These commands let the user access the remote system.
• File management commands. These commands let the user access the file system on the
remote computer. They allow the user to navigate through the directory structure, create
new directories, delete files, and so on.
• Data formatting commands. These commands let the user define the data structure, file
type, and transmission mode.
• Port defining commands. These commands define the port number for the data
connection on the client site.
There are two methods to do this.
1. First method - using the PORT command : the client can choose an ephemeral port
number and send it to the server using a passive open. The server uses that port
number and creates an active open.
2. Second method - using the PASV command : the client just asks the server to first
choose a port number. The server does a passive open on that port and sends the
port number in the response
• File transfer commands. These commands actually let the user transfer files.
• Miscellaneous commands. These commands deliver information to the FTP user at the
client site.
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 explanations.
• The three digits are represented as xyz.
• The meaning of each digit is described below.
• First Digit The first digit defines the status of the command. One of five digits can be used
in this position:
1. 1yz (positive preliminary reply). The action has started. The server will send another
reply before accepting another command.
2. 2yz (positive completion reply). The action has been completed. The server will
accept another command.
3. 3yz (positive intermediate reply). The command has been accepted, but further
information is needed.
4. 4yz (transient negative completion reply). The action did not take place, but the
error is temporary. The same command can be sent later.
5. 5yz (permanent negative completion reply). The command was not accepted and
should not 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:
1. x0z (syntax).
2. x1z (information).
3. x2z (connections).
5. x4z (unspecified).