I believe that many students who are exposed to the FTP protocol for the first time will have a feeling: FTP is a very simple protocol at first glance, but if you look closely, you will find that the ftp protocol is not very simple.
So today we are going to talk about this FTP protocol that makes many beginners of the network depressed. First of all, we first understand the concept of the FTP protocol.
FTP (File Transfer Protocol) is a standard protocol for file transfer on the Internet. The TCP protocol used by the FTP protocol is used as the transfer protocol to ensure that the data transmitted through the FTP protocol is reliable. The simple understanding is that we can upload and download files on the network using the FTP protocol.
FTP is divided into control connection and data connection. There are two different data transmission modes on data connection: active mode and passive mode.
Today we mainly talk about the active mode of FTP. FTP active transfer mode is also called PORT mode, which is also the default transfer mode of FTP protocol. As we all know, before data transmission through the FTP protocol, two connections need to be established: one is a control connection; the other is a data connection. Among them, the characteristics of the FTP active transmission mode in these two connections are as follows:
1) FTP client initiatively initiates the establishment of a control connection
2) FTP server initiatively initiates the establishment of a data connection
Then we will introduce the specific content of these two connections in detail through experiments:
1. Establish a control connection
Figure: The control connection is established successfully
As shown in the figure above: the FTP active mode control connection is initiated by the FTP client, the port number of the FTP client initiated connection is randomly generated by the system (50253); and the port of the FTP server is the well-known port number 21 (the port number It is the port number used by FTP to establish a control connection); after the three-way TCP handshake between the FTP client and the FTP server, the control connection between the FTP client and the FTP server is established successfully.
2. Active connection parameter transfer
When the control connection between the FTP client and FTP server is established successfully, the next step is to establish a data connection, because only after the data connection is established can they upload and download file information, but before establishing a data connection, the FTP client must Pass some parameter information to the FTP server to determine the temporary port number used by the FTP client when establishing a data connection.
Figure: PORT parameters
As shown in the figure above: FTP client actively sends PROT commands to FTP server through the established control connection. At this time, the port information of FTP client is still randomly generated by the system (49323), and the interface of FTP server is still the well-known port number 21. The passed PORT command parameter content is (12,1,1,2,197,118). Among them, 12.1.1.2 represents the FTP client, and through the formula 197*256+118=50550, the port number 50550 calculated by the formula is the port number used by the FTP client when establishing a data connection later.
3. Establish a data connection
Figure: Data connection established successfully
As shown in the figure above: the data connection in the FTP active mode is initiated by the FTP server. At this time, the port number of the FTP server is the well-known port number 20 (the port number is used for FTP data connection), and the port number of the FTP client is The port number (50550) calculated by the PORT parameter, after the three-way TCP handshake between the FTP client and the FTP server, the FTP data connection is established successfully.
When the data connection is established successfully, the FTP server and FTP client can upload and download files at this time.
test:
At this time, the fuquit file is created on the FTP server, and the china file is created on the FTP client.
At this point, we let the FTP client download the funquit of the FTP server, and let the FTP client upload the china file to the FTP server