FTP protocol
The FTP protocol uses two separate TCP connections, one dedicated to sending FTP commands, called control connections, and the other dedicated to transmitting data, called data connections.
1)Control connection
When the client wants to establish an upload/download data transmission with the FTP server, it first initiates a connection establishment request to the TCP port 21 of the server. The FTP Server accepts requests from the client, after the connection is established, the connection is called an FTP control connection.
2)Data Connection
After the FTP control connection is established, you can start transferring files. The file transfer connection is called an FTP data connection. FTP data connection is the process of FTP data transmission. It has two transmission modes.
The active connection process is that the client sends a connection request to the FTP port of the server (21 by default). The server accepts the connection and establishes a command link. When data needs to be transmitted, the client uses the PORT command on the command link to tell the server: "I opened port XXXX and you came to connect to me ". The server sends a connection request from Port 20 to port XXXX of the client and establishes a data link to transmit data. (This is the transmission mode of Most FTP clients)
PASV (passive) connection process: the client sends a connection request to the FTP port of the server (21 by default). The server accepts the connection and establishes a command link. When data needs to be transmitted, the server uses the PASV command on the command link to tell the client: "I opened port XXXX, and you came to connect to me ". Therefore, the client sends a connection request to port XXXX of the server and establishes a data link to transmit data.
Example:
Port mode:
Figure 1 Missing
In step 2, the client's command port establishes a connection with the FTP server's command port and sends the command "port 1st ". In step 2, the FTP server returns an "Ack" to the client's command port ". In step 2, the FTP server initiates a connection from its own data port (20) to the data port (3rd) previously specified by the client, the client returns an "Ack" to the server in step 3 ".
PASV mode:
Figure 2 missing
In step 2, the client's command port establishes a connection with the server's command port and sends the command "PASV ". In step 2, the server returns the "Port 2nd" command to tell the client (server) which port is used to listen for data connections. In step 2, the client initializes a data connection from its own data port to the data port specified by the server. Finally, the server returns an "Ack" response to the client's data port in step 3.
----------------------------------------------------------------
The main Commands used are user, pass, type, size, rest, CWD, PWD, RETR, PASV, port, and quit;
Remarks: The difference between active and passive modes lies in the convenience and security of Active Server Management. A port can be connected to the outside, so it is a common mode, while a passive port is better managed by the client.