Application Layer – File Transfer Protocol (FTP client and FTP server communication) and Trivial File Transfer Protocol (TFTP)
Howdy fellas !!
In the earlier posts, we have seen the detailed functioning of an email application. Now we will see the next important feature of the application layer i.e the File Transfer Protocol (FTP) and Trivial File Transfer Protocol (TFTP) .
There is a standard mechanism provided by the internet for copying a file from one host to another host. Further, the greatest volume of data exchange on the Internet today is due to file transfer . In this post, we gonna see this feature in detail.
File Transfer Protocol (FTP) is basically the standard mechanism provided by TCP/IP for copying a file from one host to another. But this process is not that simple as it seems.
Firstly we should understand the limitations that may exist while transferring files from one system to other:
- Two systems may use different file conventions.
- The text and data may be represented in a different way.
- Two systems may have different directory structures.
FTP is a solution to all these problems with an efficient approach. FTP differs from other client/server applications such that it establishes two connections between the hosts.
It establishes two types of connections between the client and server(read FTP client and FTP server) . One of them is used for data transfer and the other will be used for control information (commands and responses).
The control connection mainly uses simple rules of communication . We need to first transfer only a line of command or a line of response at a time. On the other hand, data connection uses more complex methods due to the use of different types of data being transferred.
FTP uses two well-known TCP ports, port 21 is used for the control connection, and port 20 is used for the data connection.
Note : FTP uses the services of TCP. It requires two TCP connections(port 20 and port 21)
Basic Model of File Transfer Protocol (FTP client and FTP server components)
The FTP client consists of three blocks :
- User interface
- Control process and
- Data transfer process
The FTP server consists of two components :
- Server control process and
- Server data transfer process
The control connection connects the control processes while the data connection connects the data transfer process (refer to the model above).
The control connection is active for the entire duration of the interaction of the FTP server and FTP client. The data connection is first activated (initiated), then the file will be transferred and lastly, the data connection is closed. This sequence of events repeats for each file transfer over a FTP session.
In a nutshell, we can say that while the control connection is open, the data connection can be opened and closed multiple times if several files are to be transferred.
This connection remains active for the complete FTP session between a FTP server and FTP client. Port 21 of TCP connection has been used in this connection. The IP uses minimum delay type service to provide efficient communication between FTP server and FTP client.
FTP uses port 20 of TCP connection for this service. This connection will be initiated when the data is ready to be transferred and it is closed when the transfer is over.
Unlike its counterpart (control connection), this connection will be opened and closed many times(and not always) as per the requirement.
Communication in FTP (FTP client and FTP server working principle)
FTP operates in a client-server model configuration. The two workstations (computer or any other device) involved in communication may be different in character sets, working environment (operating system), file structures etc.
So at first FTP has to make them compatible with efficient file transferring to happen.Thus we now understand the underlying principles for both control and data connections (both of them are different from each other).
Communication over control connection
FTP uses the same approach as SMTP to communicate across the control connection. It uses the 7-bit ASCII character set. Communication is achieved through commands and responses.
This simple method is far adequate for the control connection because we send only one command (or response) at a time. Each command or response is only one short line, so no need to worry about file format or file structure.
Communication over data connection
This connection has been established for the data transfer(files) between two connecting computers. For the FTP client will first define the following:
- Type of file to be transferred
- Structure of data in the file
- Mode of transmission
File transfer occurs over the data connection under the control of the commands sent over the control connection.Let us understand each of this one by one:
File Types in FTP
FTP use one of the following file types for transfer of data over data connection:
- ASCII file
- EBCDIC file
- Image file
ASCII file is a text file, the image file is the default format for transferring the binary files. With ASCII and EBCDIC files one or more attributes should be added for defining the printability of the file. EBCDIC file can be transferred if both ends use EBCDIC encoding.
Data structures in FTP
FTP use one of the following data structures :
- File structures(default)
- Record structure
- Page structure
The file has no structure. It is only a stream of bytes. In record structure, the file is divided into records.(suitable only for text files). In page structure , a file I divided into pages that will store and accessed randomly (or sequentially).
Transmission Mode in FTP
FTP uses one of the following modes to transfer files:
- Stream mode
- Block mode
- Compressed mode
In stream mode , the data is delivered from FTP to TCP in the form of a continuous stream of bytes. TCP chops this data into small segments of the required size stream. This mode is the default mode of transmission.
In block mode, data transfer from FTP to TCP in the form of data blocks. Each such block is preceded by a 3 byte header.
In compressed mode, the big files can be compressed. A run-length encoding is used for compression.
FTP File Transfer
File transfer takes place over the data connection and the commands are sent over the control connection. The commands supervise the data transfer.
File transfer in FTP basically means one of the following:
- Retrieving a file: FTP server will copy a file onto an FTP client.( It is done under the supervision of the RETR command)
- Storing a file : A file can be copied from FTP client to the FTP server.(It is done under the supervision of the STOR command)
- A server sends a list of directory or file names to the client. FTP treats such a list of the directory also as a file.(This is done under the supervision of the LIST command)
Following commands are used for copying files using FTP
|Get||Copy a file from remote host to local host|
|M get||Copy multiple files from the remote host to local host|
|Put||Copy a file from local host to remote host|
|M put||Copy a multiple files from local host to remote host|
FTP commands used to connect to remote host are as follows :
|Open||Select the remote host and initiate login process|
|User||Identify the remote user ID|
|Pass||Authenticate the user|
|Site||Send the information to the remote host|
FTP commands used to end a FTP session:
|Quit||Disconnect from the remote host and terminate FTP|
|Close||Disconnect from the remote host but leave FTP client
To use FTP, a user needs to have an account (user name) along with a password on the remote server. Some sites generally have a set of files available for public access, to enable anonymous FTP. To access these files, any user doesn’t need to have an account or password.
Instead, the user can use anonymously as the user name and then guest as the password. User access to the system is very limited. Some sites further allow anonymous users only a subset of commands. For example, most sites allow the user to copy some files, but do not allow navigation through the directories.
Trivial File Transfer Protocol (TFTP)
In the trivial file transfer protocol (TFTP) , no authentication is required for the user.There is also no separation of data and control as in the case of FTP.This is frequently used by devices without any permanent storage. Due to the lack of any security features, the use of TFTP is generally restricted.
TFTP uses the unreliable transport protocol UDP (user datagram protocol) for the transportation of data.Each message in TFTP consists of separate UDP datagram. The initial two bytes declare the message type (whether to download/upload any file etc). At the start TFTP client sends a request to upload/download a file from UDP port to UDP port 69 of the TFTP server.
After receiving the request, the TFTP server picks up the UDP port of its own and uses this port to communicate with the TFTP client. Thus both TFTP client and server establishes connection for file exchange. TFTP transfers data in a block of 512 bytes.
Further, a 2-byte long sequence number has been associated with each block of data. There is also an acknowledgment received before sending the next block.
If an acknowledgment is not received, then the same block will be re-transmitted. If the receiver received any block of size less than 512 bytes, then it assumes that the end of files has been reached.
Finally we have reached the end of this post. In the next post, we will further see a detailed analysis of many commonly used terms that we normally use(regarding internet) in our daily life.
Aric is a tech enthusiast , who love to write about the tech related products and ‘How To’ blogs . IT Engineer by profession , right now working in the Automation field in a Software product company . The other hobbies includes singing , trekking and writing blogs .