Basic introduction to FTP protocol

basic introduction

FTP (File Transfer Protocol) is the most widely used file transfer protocol on the Internet. FTP provides interactive access, allowing customers to specify the type and format of files (for example: specify whether to use ASCII code) and allows files to have Access permissions (for example: users accessing files must be authorized and enter valid passwords). FTP shields the details of each computer system, so it is suitable for transferring files between any computers in heterogeneous networks. RFC959 has long become a The formal standard of the Internet. In the early stages of the development of the Internet, using FTP to transfer files accounted for about one-third of the entire Internet traffic, and the traffic generated by email and domain name systems was still smaller than the traffic generated by FTP. It was not until 1995 that the traffic volume of WWW exceeded FTP for the first time.

Protocol introduction

A basic application in a network environment is to copy files from one computer to another computer that may be far away. At first glance, transferring files between two hosts seems to be a very simple matter, but in fact it is often very complex. Difficult because numerous computer manufacturers have developed hundreds of file systems that are very different. Commonly encountered problems are:

  • Different access control methods
  • Computers store data in different formats
  • The directory structure of files and the rules for file naming are different.
  • For the same file access function, the operating system uses different commands

File Transfer Protocol FTP only provides some basic services for file transfer. It uses TCP's reliable transport service. The main function of FTP is to reduce or eliminate incompatibilities in processing files under different operating systems. FTP uses the client-server method. One FTP server process can provide services to multiple client processes at the same time. The FTP server process consists of two parts: the main process is responsible for accepting new requests, and there are several slave processes responsible for processing single requests. The process steps are as follows:

  • Open port (21) so that the client process can connect
  • The next step is to wait for the client process to issue a connection request.
  • Start the slave process to process the request from the client process. The slave process will terminate after processing the request from the client process. However, the slave process may also create some other child processes as needed during operation.
  • Return to the waiting state and continue to accept requests from other client processes. The main process and slave processes are processed concurrently.

The working situation of FTP is shown in the figure below. The oval circle in the figure represents the process running in the system. The server side in the figure has two slave processes: the control process and the data transfer process. For the sake of simplicity, the main process on the server side is not shown. In addition to the control process and the data transfer process, the client also has a user interface process to interface with the user. When performing file transfer, two parallel TCP connections must be established between the FTP client and the server: "control connection" "and "data connection", the control connection remains open during the entire session. The transfer request issued by the FTP client is sent to the control process on the server side through the control connection, but the control connection is not used to transfer files, but is actually used for transmission The file is a "data connection". After receiving the file transfer request from the FTP client, the server-side control process creates a "data transfer process" and a "data connection" to connect the client and the server. The data transfer process on the end of the data transfer process actually completes the file transfer. After the transfer is completed, it closes the "data transfer connection" and ends the operation. Since FTP uses a separate control connection, the control information of FTP is out-of-band (out of band) transmitted

When the client process sends a connection establishment request to the server process, it needs to find the well-known port 21 to connect to the server process. At the same time, it also tells the server process its own other port number to establish a data transfer connection. Then the server process uses its own port number to transfer data. Familiar with port 20, establish a data transfer connection with the port number provided by the client process. Since FTP uses two different port numbers, there will be no confusion between the data connection and the control connection. The main benefit of using two independent connections is that the protocol It is simpler and easier to implement. At the same time, you can also use the control connection to control the transfer of files when transferring files. For example: the client sends a "request to terminate transmission". FTP is not optimal for all data transfers. For example: an application running on computer A wants to add a line of information to the end of a large file on remote computer B. If FTP is used, the file should be removed from the computer first. B transfers it to computer A, adds this line of information, and then uses FTP to transfer the file to computer B. It takes time to transfer such a large file back and forth. In fact, this transfer is unnecessary because computer A is not using However, the network file system NFS uses another idea. NFS allows the application process to open a remote file and start reading and writing data at a specific location in the file. In this way, NFS allows the user to only copy A very small fragment of a large file without copying the entire large file. For the above example, the NFS client software in computer A sends the data to be added and the request to write data behind the file to the NFS server in remote computer B. The NFS server updates the file and returns the response information, which is transmitted over the network. only a small amount of modified data.

Protocol extension

There is also a simple file transfer protocol TFTP (Trivial File Transfer Protocol) in the TCP/IP protocol suite. It is a small and easy-to-implement file transfer protocol. Version 2 of TFTP is the official standard of the Internet [RFC 1350]. Although TFTP also uses the client-server method, it uses UDP datagrams, so TFTP needs its own error correction measures. TFTP only supports file transfer and does not support interaction. TFTP does not have a huge command set and does not have the function of listing directories. The user cannot be authenticated.

TFTP can be used in a UDP environment. For example, when programs or files need to be downloaded to many machines at the same time, TFTP is often needed. At the same time, the TFTP code occupies a small amount of memory, which is suitable for smaller computers or some special-purpose equipment. It is very important that these devices do not need a hard disk and only need a small-capacity read-only memory that has solidified TFTP, UDP and IP. After the power is turned on, the device executes the code in the read-only memory and broadcasts a TFTP request on the network. The TFTP server sends a response which includes an executable binary program. After receiving this file, the device puts it into memory and then starts running the program. This approach increases flexibility and reduces overhead.

The main features of TFTP are:

  • Very simple header to use
  • Can read or write files
  • Support ASCII code or binary transmission
  • Data packets are numbered sequentially, starting from 1
  • Each data packet transmitted contains 512 bytes of data, but the last one may be less than 512 bytes.

TFTP works very much like the stop-and-wait protocol. After sending a file block, it waits for confirmation from the other party. When confirming, the confirmed block number should be specified. After sending the data, if the confirmation is not received within the specified time, the data PDU will be resent. If the party sending the confirmation PDU cannot receive the next file block within the specified time, it must resend the confirmation PDU. This ensures that the file transmission will not fail due to the loss of a certain datagram.

Summary at the end of the article

In this article, we briefly introduce the FTP protocol, discuss its working principle and derive the TFTP protocol. Later we will introduce how to build the FTP server and how to use the FTP client.

Guess you like

Origin blog.csdn.net/Fly_hps/article/details/135012051