


FTP active mode and passive mode - Why can't I connect to the FTP server?
FTP is different from general services. This service needs to open two ports at the same time. One port is the command channel and the other port is the data transmission channel. According to the different establishment of data transmission channels, it is divided into active mode and passive mode. Here, we describe in detail the workflow of active mode and how to solve problems when encountering them.
Active mode process
Establishment of command channel. The client will randomly select a port greater than 1024 to establish a connection with the server's port 21. Once the connection is established, the client can use the connection to execute commands on the ftp service, such as querying file names, uploading files, downloading files, etc. Commands are executed through this channel.
Notify the server to use active mode. Port 21 is only used for command execution. For files that really need to be transferred, a different port needs to be opened. The client will randomly open another port for file transfer, and then notify the ftp server of two pieces of information through port 21. The client user's file transfer port uses active mode for file transfer.
The ftp server actively establishes a connection to the client. When the ftp server knows the two pieces of information, it will actively establish a connection with the client through port 20. Once the connection is established, files can be transferred through the connection.
Problems you may encounter in active mode
If you cannot connect to the ftp server in active mode, there may be the following situations:
The server port is not started
Server firewall
-
The LAN where the client is located has NAT conversion
In active mode, the generally opened ports are 21 (command channel) and 20 (file transfer channel). Both ports are indispensable. In addition, the firewall also needs to allow these two ports. For the client host, you can use telnet to test whether these two ports are open.
Problems with ports and firewalls are relatively easy to solve, but NAT conversion problems are difficult to solve. Let's look at how NAT conversion causes problems. Because the establishment of the command channel is initiated by the client, the channel can be successfully established. However, when the server actively establishes a data channel to the client, the server knows the NAT IP, not the client's IP. Therefore, the server will send an active connection request to one of the NAT ports (for example, port 1042) using port 20. However, NAT did not open that port, so the active connection establishment failed. So, how to solve this problem? Just use passive mode.
Passive mode process
Establishment of command channel. This stage is the same as active mode.
The client issues a PASV link request. The client sends a PASV passive mode request to the server through the command channel and waits for the server's response.
The server starts the data port and informs the client. When the server receives the client's PASV request, it will start a port for data transmission. This port can be random (1024~65535) or specified. Then, tell the client through the command channel.
The client starts the data port and establishes a connection with the server. The client receives the information from the server and knows the port used by the server for data transmission. At this time, the client will randomly open a port greater than 1024, and then establish a connection with the server through this port.
For more related technical articles, please visit the linux system tutorial column!
The above is the detailed content of FTP active mode and passive mode - Why can't I connect to the FTP server?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

1. Install nginx 2. Install vsftpd 3. Modify the nginx configuration file nginx.conf 3.1 Add the ftp user userftpuser in the first line; 3.2 Configure the relevant path server{ listen80; #nginx proxy port server_namelocalhost; #ftp server address location/images{root /home/ftpuser; #The absolute path of the folder of the proxy ftp server indexftpuser; #Set the welcome page

With the rapid development of the Internet, File Transfer Protocol (FTP) has always been an important file transfer method. In Go language, using FTP to transfer files may be a need of many developers. However, maybe many people don't know how to use FTP in Go language. In this article, we will explore how to use FTP in Go language, from connecting to FTP server to file transfer, and how to handle errors and exceptions. Create FTP connection In Go language, we can use the standard "net" package to connect to FTP

PHP and FTP: Achieve file sharing among multiple departments in website development. With the development of the Internet, more and more companies are beginning to use website platforms for information release and business promotion. However, the problem that arises is how to achieve file sharing and collaboration among multiple departments. In this case, PHP and FTP become one of the most commonly used solutions. This article will introduce how to use PHP and FTP to achieve file sharing among multiple departments in website development. 1. Introduction to FTP FTP (FileTransferPr

The ftp commands under Linux include: 1. ftp command; 2. close command; 3. disconnect command; 4. open command; 5. user command; 6. account command; 7. bye command; 8. quit command; 9. help command ;10. rhelp command; 11. ascii command; 12. binary/bi command; 13. bell command, etc.

How to compare directories and files on an FTP server through PHP In web development, sometimes we need to compare local files with files on the FTP server to ensure consistency between the two. PHP provides some functions and classes to implement this functionality. This article will introduce how to use PHP to compare directories and files on an FTP server, and provide relevant code examples. First, we need to connect to the FTP server. PHP provides the ftp_connect() function to establish an FTP server

How to use PHP to implement FTP file upload progress bar 1. Background introduction In website development, file upload is a common function. For the upload of large files, in order to improve the user experience, we often need to display an upload progress bar to the user to let the user know the file upload process. This article will introduce how to use PHP to implement the FTP file upload progress bar function. 2. The basic idea of implementing the progress bar of FTP file upload. The progress bar of FTP file upload is usually calculated by calculating the size of the uploaded file and the size of the uploaded file.

linux ftp530 means linux ftp login error 530. The solution is: 1. Check "cat /etc/shells" to see if your user's home directory and login shell are there. If not, add them; 2. Check "/var /log/secure" file and reset the password expiration time.

1. Environment: ftp is vsftp. The username is set to test. The restricted path is /home/test2. Create a user: under the root user: useradd-d/home/testtest#Add user test, and set the home directory of the test user to /home/testpasswdtest#Set a password for the test user3. Change the corresponding permission settings of the user: 1.usermod-s/sbin/nologintest#Limit user test cannot telnet, only ftp2.usermod-s/bin/bashtest#Return to normal for user test 3.usermod-d
