I believe there is no more basic protocol than the FTP file transfer protocol. Therefore, we must have some contact with such an agreement. So many servers and sites will be used for construction. If you still don't know the details, let's take a look at the article.
1. FTP File Transfer Protocol Overview
FTP is short for File Transfer Protocol. FTP is a specific application of TCP/IP. It works on the Seventh Layer of the OSI model and the fourth layer of the TCP model, that is, the application layer uses TCP transmission instead of UDP. The FTP connection is reliable and connection-oriented, providing reliable guarantee for data transmission 。
The FTP working mode is similar to the Client/Server mode. Unlike most other TCP applications, FTP uses two TCP connections between the client and the server-control connections and data connections, the control connection exists throughout the process of customer-server interaction, and data connections are created only when files or directories are transmitted, the connection is closed after it is used up. The control connection is used to send commands to the server and wait for the server to respond. The data connection is used to establish a data transmission channel 。
2. Port mode of FTP File Transfer Protocol
Depending on whether the Port or Passive mode is used, FTP uses different TCP Port numbers 。
FTP Port Mode
The FTP File Transfer Protocol in Port mode is as follows:
1. The client sends a TCPSYN (TCP synchronization) packet to the well-known FTP control port 21 of the server segment, and the client uses the temporary port as its source port;
2. the server sends a syn ack (synchronous confirmation) packet to the client. The source port is 21 and the destination port is the temporary port used on the client;
3. The client sends an ACK packet. The client uses this connection to send FTP file transfer protocol commands, and the server uses this connection to send FTP responses;
4. When a user requests a List request or initiates a request to send or accept files, the client software uses the PORT command, which contains a temporary PORT, the client wants the server to use this temporary PORT when opening a data connection. The PORT command also contains an IP address, which is usually the customer's own IP address, in addition, FTP supports the third-party mode. In the third-party mode, the client tells the server to open a connection with another host;
5. the server sends a SYN packet to the temporary PORT of the client. The source PORT is 20, and the temporary PORT is the temporary PORT number sent from the client to the server in the PORT command;
6. The client uses the source port as the temporary port, and the destination port is 20 to send a syn ack packet;
7. The server sends an ACK packet;
8. The host sending data sends data through this connection, and the data is sent in the form of a TCP segment (Note: segment, layer 4th PDU) (some commands, for example, STOR indicates that the client needs to send data, and RETR indicates that the server sends data). These TCP segments must be ACK confirmed by the other party (Note: Because TCP is a connection-oriented Protocol );
9. After the data transmission is complete, the host sending the data end the data connection with a FIN command. The FIN Command needs to be confirmed by ACK on another host, another host also sends a FIN command, which also needs to send data to the host with ACK for confirmation;
10. The FTP File Transfer Protocol stipulates that after the client ends, the client uses the FIN command to close a control connection, and the server uses the ACK package to confirm the FIN of the client, the server also sends its FIN, and the client uses ACK for confirmation 。