This is the 28th day of my participation in the August Challenge

Introduction of the FTP

File Transfer Protocol (FTP) is a Protocol in the TCP/IP group. The FTP protocol consists of two parts: the FTP server and the FTP client. The FTP server is used to store files. Users can use the FTP client to access resources on the FTP server through FTP. In the development of websites, usually use FTP protocol to upload Web pages or programs to the Web server. In addition, FTP is usually used to transfer large files over the network because of its high transmission efficiency.

By default, FTP uses TCP ports 20 and 21. 20 is used for data transmission and 21 is used for control information transmission. However, whether 20 is used as the data transfer port depends on the transfer mode used by FTP. If active mode is used, the data transfer port is 20. If passive mode is used, the final port to be used must be negotiated between the server and client.

FTP supports two modes. The first mode is called Standard mode, also known as PORT mode and active mode, and the second mode is called Passive mode, also known as PASV mode. The Standard FTP client sends the PORT command to the FTP Server, and the Passive FTP client sends the PASV command to the FTP Server to ensure normal file transfer.

FTP active mode

We use Huawei’s simulator Ensp to do a small experiment.

There are two FTP three-way handshakes. The first TCP three-way handshake is for the control layer, and the second TCP three-way handshake is for the data layer

(1) The server opens port 21 and waits for connection.

(2) The client (100.1.12.1) initiates the request to establish the control connection, and the server responds to the request and establishes the control connection, using TCP three-way handshake (the first TCP three-way handshake);

Random port calculation

You can see that ports are 10,0,0,2,8,6

Random ports are calculated as follows :8 x 256+6=2054

(3) The client sends the PORT command through the control connection (with its own IP address and temporary PORT in the application layer data) to tell the server the temporary PORT number of the client data connection

(4) Port 20 of the server establishes a data connection with the client, using TCP three-way handshake (second TCP three-way handshake);

Click logout to disconnect the control port

FTP passive mode

There are two FTP three-way handshakes. The first TCP three-way handshake is for the control layer, and the second TCP three-way handshake is for the data layer

(1) The server opens port 21 and waits for connection

(2) the client initiates the establishment request of the control connection, and the server responds to the connection and establishes the control connection, using TCP three-way handshake (the first TCP three-way handshake);

(3) The client sends command word PASV through the control connection to inform the server to be in passive mode;

(4) The server responds by telling the client the temporary port number of the server data connection (2060);

(5) The client establishes a data connection with the temporary port of the server, using TCP three-way handshake (the second TCP three-way handshake);