(Transfer) What is the Passive mode and Active mode of FTP

What is Passive Mode and Active Mode of FTP

  From: http://blog.sina.com.cn/s/blog_5ceb51480102vpm8.html
 
 
       Because FTP is often used in the project, FTP data is operated through some related clients such as CuteFTP, Fillzilla, WinSCP and other tools or Linux commands, but the working mode of FTP is a bit vague. Let's familiarize yourself with the active and passive modes of FTP. What you need to know is that FTP is based on TCP services and does not support UDP. FTP-File Transfer Protocol, file transfer protocol.
 
1. Two working modes of FTP
FTP has two working modes: active mode (Active FTP) and passive mode (Passive FTP)
 
      In active mode, the FTP client randomly opens a port N greater than 1024 to initiate a connection to port 21 of the server, then opens port N+1 for monitoring, and sends the PORT N+1 command to the server. After the server receives the command, it will use its local FTP data port (usually 20) to connect to the port N+1 specified by the client for data transmission.
 
      In passive mode, the FTP client randomly opens a port N greater than 1024 to initiate a connection to port 21 of the server, and also opens port N+1. Then send the PASV command to the server to inform the server that it is in passive mode. After the server receives the command, it will open a port P greater than 1024 for monitoring, and then use the PORT P command to notify the client that its own data port is P. After the client receives the command, it will connect to the port P of the server through port N+1, and then perform data transmission between the two ports.
 
      In general, active mode FTP means that the server actively connects to the client's data port, and passive mode FTP means that the server passively waits for the client to connect to its own data port.
 
      Passive mode FTP is usually used when the FTP client behind the firewall accesses the external FTP server, because in this case, the firewall is usually configured to not allow the outside world to access the host behind the firewall, but only allow the host behind the firewall to initiate. The connection request goes through. Therefore, in this case, active mode FTP transfer cannot be used, while passive mode FTP can work well.
 
      Generally, the connection mode of connecting to FTP client software is Passive by default. That is, the FTP client sends a connection request to the service port (21 by default), and the server establishes a command link after receiving the request. Then the server sends a message through the command link to tell the client that a certain port of the server is open between (1025-65535), and establishes a data link with the client, so that the client can upload and download data. This passive means that the client passively receives the message from the server before it can start transmission. In general, it may be blocked by the server firewall. In active mode, PORT means that the FTP client sends a connection request to the service port (default is 21), and the server establishes a command link after receiving the request. This process is the same as the passive connection. Then the client sends a message through the command link to tell the server that the client is generally open on port 20. After the server receives the message, it connects to the port and establishes a data link to upload and download data. This initiative means that the client actively opens port 20 and initiates a request to establish data transmission with the server. This mode may be limited by the firewall of the client, and also cannot use the FTP service when surfing the Internet with the proxy, because the port of the proxy server that the server connects to after receiving the request from the client.
 
2. In-depth description of FTP mode
      Active FTP is good for the management of the FTP server, but not good for the management of the client, because the FTP server attempts to establish a connection with the client's high-order random port, which is likely to be blocked by the client's firewall. Passive FTP is good for the management of the FTP client, but it is not good for the management of the server, because the client needs to establish two connections with the server, one of which is connected to a high random port, and this port is likely to be blocked by the firewall of the server.
 
      Fortunately, there are compromises. Since FTP server administrators need their server to have the most client connections, passive FTP must be supported. We can reduce the exposure of the server's high-order ports by specifying a limited port range for the FTP server. This way, any ports that are not in this range will be blocked by the server's firewall. While this doesn't eliminate all dangers against the server, it greatly reduces them.
 
      In short: Active Mode (PORT) and Passive Mode (PASV). The active mode is to initiate a connection from the server to the client; the passive mode is that the client initiates a connection to the server. The common point of the two is that they both use port 21 for user authentication and management. The difference lies in the way of data transmission. The data port of the FTP server in PORT mode is fixed at 20, while the PASV mode is random between 1025-65535.
 
3. The solution and principle of FTP active mode and passive mode
      FTP is an acronym for File Transfer Protocol, which is used to transfer files between two computers. Compared to HTTP, the FTP protocol is much more complex. The reason for the complexity is that the FTP protocol uses two TCP connections, one is the command link, which is used to transfer commands between the FTP client and the server; the other is the data link, which is used to upload or download data.
 
The FTP protocol has two working modes: PORT mode and PASV mode, which means active and passive in Chinese.
 
The connection process in PORT (active) mode is: the client sends a connection request to the server's FTP port (default is 21), and the server accepts the connection and establishes a command link. When it needs to transmit data, the client uses the PORT command on the command link to tell the server: "I have opened the XXXX port, you come and connect to me". So the server sends a connection request from port 20 to the XXXX port of the client to establish a data link to transmit data.
 
The connection process in PASV (passive) mode is: the client sends a connection request to the server's FTP port (default is 21), and the server accepts the connection and establishes a command link. When the data needs to be transmitted, the server uses the PASV command on the command link to tell the client: "I opened the XXXX port, you come to connect me". So the client sends a connection request to the XXXX port of the server to establish a data link to transmit data.
 
General description:
Active mode: the server knocks on the door of the client, and then the client opens the door;
Passive mode: The client knocks on the door of the server, and the server opens the door.
 
Therefore, if you access the Internet through a proxy, you cannot use active mode, because the server is knocking on the door of the Internet proxy server, not the client's door, and sometimes, the client is not easy to open the door, because there is a firewall. Block, unless the client opens high-end ports greater than 1024 and use active mode to download, please do not tick the passive mode (PASV) of the download tool, it is OK to download in active mode, if there is another error, then passive mode Actively convert each other.
 
Common FTP client software's PASV closing method. Most FTP clients use the PASV mode by default, which means passive mode. In the settings of most FTP clients, the common word is "PASV" or "passive mode".
 
IE: Tools -> Internet Options -> Advanced -> "Use Passive FTP" (requires IE6.0 or above to support).
 
CuteFTP: Edit -> Setting -> Connection -> Firewall -> “PASV Mode”
 
Or File -> Site Manager, select the site on the left -> Edit -> "Use PASV mode"
 
FlashGet: Tools->Options->Proxy->Direct Connection->Edit->"PASV Mode"
 
FlashFXP: Options -> Preferences -> Proxy/Firewall/Identification -> "Use Passive Mode"
 
Or Site Administration -> Corresponding Site -> Options -> "Use Passive Mode"
 
or quick connect -> toggle -> "use passive mode"
 
LeapFTP: Option ->Preferences -> General->Proxy->Use Pasv Mode
 
As can be seen from the above, the command link connection method of the two methods is the same, but the establishment method of the data link is completely different, and the complexity of FTP lies in this.
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326404861&siteId=291194637