First, the basic principles of FTP
FTP is a protocol used to transfer files. Using FTP to achieve remote file transmission, it ensures the reliability and efficiency of data transmission.
FTP transfer file process
When using FTP to transfer data, it is necessary to establish a control connection and a data connection between the server and the client
FTP active mode
The client punches in a random port (the port number is greater than 1024, called it X) and the FTP server connects to the server's command port 21 at this time. The source port is random port X on the client; the remote port is 21 on the server end
The client starts listening on the port (X + 1), and at the same time sends a port PORT command (through the server's command port 21) to the server. This command tells the server that the client is now listening on the port number and is ready to receive data on this port. This port is known as the data port
The server opens port 20 and establishes a connection with the client's data port. At this time, the source port is 20, and the source data port is (x + 1)
The client establishes a connection with the server's 20 port through the local data port, and then sends a response to the server to tell the server that it has established a connection
FTP passive mode
The passive mode of FTP is also called PASV mode, and is only enabled when the client notifies the server that it is in passive mode. Passive mode FTP connection, command connection and data connection are initiated by the client
Main steps of passive mode FTP connection
When opening an FTP connection, the client opens two arbitrary unprivileged local ports (N> 1024 and N + 1)
The first i-port is connected to the server's 21 port, but unlike the active FTP, the client will not submit the PORT command and allow the server to connect to its data port back and forth, but submit the PASV command
The result of this is that the server will open any unprivileged port (P> 1024) and send a PORT command to the client
Then the client initiates a connection from the local port N + 1 to the server's port P to transfer data
2. FTP basic configuration
FTP provides an effective way to upload and download files between the server and the client
FTP configuration
FTP transfer mode
The transmission mode defines the format of data transmission between the client and the server
ASCll mode is used to transmit text. The characters at the sending end are converted to ASCll code format before transmission , and then converted to characters after the receiving end
Binary mode is often used to send picture files and program files . The sending end can transmit these files without converting the format
FTP connection establishment process
1. Three-way handshake to establish control connection and server port 21
2. Establish a data connection, use N + 1 to establish a connection with the server's 20 port