We have already introduced the basic content about the FTP protocol. I believe you have some knowledge about this agreement. In order to further consolidate this part of basic content. We will explain the FTP workflow, mode, and method in a targeted manner.
How FTP works
FTP has two processes: control connections and data transmission. The FTP protocol does not need a port as the default connection. The HTTP port is 80, and the FTP port is 21 ). The FTP protocol requires two ports. One port serves as the control connection port, namely port 21 of FTP, which is used to send commands to the server and wait for the server to respond. The other port is used for the data transmission port, PORT Number is 20 only in PORT mode), is used to establish a data transmission channel, the main function is to send a file from the customer to the server, from the server to send a file to the customer, the slave server sends a file or directory list to the client.
FTP transmission mode
An FTP task transfers files from one computer to another, regardless of the location, connection method, or even whether the two computers use the same operating system. Assume that the two computers communicate over the ftp protocol and can access the Internet. You can use ftp commands to transmit files. There are some nuances in the use of each operating system, but the basic command structure of each protocol is the same.
There are two FTP transmission modes: ASCII transmission mode and binary data transmission mode.
The ASCII transmission mode assumes that the file being copied contains simple ASCII code text. If the file running on a remote machine is not UNIX, during file transfer, ftp usually automatically adjusts the content of the file so that the file can be interpreted as another computer that stores the text file format. However, in this case, the files being transmitted by the user are not text files. They may be programs, databases, word processing files, or compressed files. Although most of the word processing files contain text files, it also contains non-printable characters indicating the page size and font information ). Before copying any non-text files, use the binary command to tell ftp to copy them verbatim. Do not process these files. This is also the binary transfer to be discussed below.
In binary transmission, the file order is saved so that the original and copied files are one-to-one. Even if the destination machine contains files with bit sequences, it makes no sense. For example, if a macintosh transfers an executable file to a Windows system in binary mode, the file cannot be executed on the other system. If you transfer a binary file in ASCII mode, the translation will still be translated even if you do not need it. This slows down the transmission, damages the data, and makes the file unusable. On most computers, the ASCII mode generally assumes that the first valid bit of each character is meaningless, because it is not used for the combination of ASCII characters. If you transmit binary files, all bits are important .) If you know that the two machines are the same, the binary method is effective for text files and data files.
How FTP works
FTP supports two modes: Standard (PORT mode) and Passive (PASV mode ).
The FTP client in Standard mode sends the PORT command to the FTP server. The client in Passive mode sends the PASV command to the FTP Server.
The following describes how these two methods work:
In Port mode, the FTP client dynamically selects a Port usually greater than 1024) and establishes a connection with the TCP Port 21 of the FTP server, and sends commands through this channel, when the client needs to receive data, it sends the PORT command on this channel.
The PORT command contains the PORT used by the client to receive data. When transmitting data, the server connects to the specified port of the client through its TCP port 20 to send data.
The FTP server must establish a new connection with the client to transmit data.
The Passive mode is similar to the Standard mode when a control channel is established, but the Port command is not sent after the connection is established, but the Pasv command. After the FTP server receives the Pasv command, it randomly opens a high-end port number greater than 1024) and notifies the client to send data requests on this port, the client connects to the FTP server this port, the FTP server then transmits data through this port. At this time, the FTP server no longer needs to establish a new connection with the client. Many firewalls do not allow external connections when they are set. Therefore, many FTP servers located behind the firewall or on the intranet do not support the PASV mode, because the client cannot open the high-end PORT of the FTP server through the firewall, many Intranet clients cannot log on to the FTP server in PORT mode, because the slave server's TCP 20 cannot establish a new connection with the client of the internal network, it cannot work.