FTP is a type of file transfer protocol in the network protocol. That is, the download protocol we usually use. The default method used when you do not need to download software for network file transfer. How do we define the most basic download protocol? The following is a detailed explanation.
FTP protocol
In TCP/IP protocol, the TCP Port number of the FTP standard command is 21, and the Port data Port is 20. 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.
1. ASCII transmission mode: assume 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.
2. binary transmission mode: in binary transmission, the file order is saved so that the original and copied files correspond one by 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 FTPServer.
The following describes how these two methods work:
In Port mode, the FTP client first 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 through 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. FTPserver 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 temporary port, which is also called a free port, and the port number is greater than 1023 and less than 65535) and notifies the client to send data on this port, the client connects to this port of the FTP server, and the FTP Server transfers data through this port. At this time, the FTPserver 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 protocol 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.