Overview
Use either the active or passive mode to connect to a File Transfer Protocol (FTP) server.
Active mode vs. passive mode
FTP utilizes two ports, a data port and a command port, to transfer information from a client to a server. Typically, the command port uses port 21 and the data port uses port 20. When you use a different mode, however, the data port does not always use port 20.
Active
In active mode, the FTP server responds to the connection attempt and returns a connection request from a different port to the FTP client. Network Address Translation (NAT) configurations block this connection request.
Passive
In passive mode, the FTP client initiates both connection attempts. NAT configurations do not block this connection request.
Note:
If FTP users exist on the private network side of a NAT configuration, you must enable FTP's passive mode and open the passive port range in your FTP server's configuration file. You may also need to open the passive port range on your firewall.
Enable the passive port range for Pure-FTPd
To enable the passive port range on a server that uses Pure-FTPd, perform the following steps via the command line as the root
user:
- With a text editor, open the
/etc/pure-ftpd.conf
configuration file. -
Remove the comment (
#
) from the beginning of the line that contains thePassivePortRange
option. -
Set the
PassivePortRange
option to a port range that is greater than or equal to1024
.In the following example,
30000 50000
represents thePassivePortRange
option:PassivePortRange 30000 50000
Important:
We strongly recommend that you configure a large port range so that the server can process many simultaneous passive connections. For example, the Internet Assigned Numbers Authority (IANA) recommends the
49152:65534
port range. - If your FTP server exists behind a NAT configuration, set the
ForcePassiveIP
option to the FTP server's public IP address.In the following example,
10.3.5.333
represents your FTP server's public IP address:ForcePassiveIP 10.3.5.333
Warning:
We strongly recommend that you only use this option if your server exists behind a NAT configuration. This option prevents connections to other IP addresses on the server, and connections via domains that resolve to other IP addresses. If you set an IP address for the
ForcePassiveIP
option, you can only connect to the FTP server via that IP address. -
Save the changes to the configuration file.
-
Run the following commands to allow connections through the passive port range of your server's firewall:
12iptables -I INPUT 2 -p tcp --dport 30000:50000 -j ACCEPT
service iptables save
Important:
If your FTP server exists on a CentOS 7, CloudLinux™ 7, or Red Hat® Enterprise Linux (RHEL) 7 server, run the following commands to allow connections through the passive port range that you set:
123firewall-cmd --permanent --zone=public --add-service=ftp
firewall-cmd --permanent --add-port=30000-50000/tcp
firewall-cmd --reload
-
Run the
/usr/local/cpanel/scripts/restartsrv_ftpserver
command to restart the FTP server. -
To make these changes permanent, you must append the passive ports to the configuration file. To do this, run the following commands as the
root
user:12echo
"PassivePortRange: 30000 50000"
>>
/var/cpanel/conf/pureftpd/main
/usr/local/cpanel/scripts/setupftpserver
pure-ftpd --force
-
If your FTP server exists behind a NAT configuration, run the following command:
echo "ForcePassiveIP: 10.3.5.333" >> /var/cpanel/conf/pureftpd/main
Note:
10.3.5.333
represents your FTP server's public IP address.
For more information about how to edit your Pure-FTPd configuration, read our FTP FAQ documentation.
Enable the passive port range for ProFTPd
To enable the passive port range on a server that uses ProFTPd, perform the following steps via the command line as the root
user:
- With a text editor, open the
/etc/proftpd.conf
configuration file. -
Add the following line to the first section of the configuration file, where
30000 50000
represents thePassivePorts
option::PassivePorts 30000 50000
-
If your FTP server exists behind a NAT configuration, add the following additional lines to the configuration file:
12MasqueradeAddress example.com
MasqueradeAddress 10.3.5.333
Notes:
- The
MasqueradeAddress
lines specify the FTP server's public IP address. example.com
represents your FTP server's hostname.10.3.5.333
represents your FTP server's public IP address.
- The
- Save the changes to the configuration file.
-
Run the following commands to allow connections through the passive port range of your server's firewall:
12iptables -I INPUT 2 -p tcp --dport 30000:50000 -j ACCEPT
service iptables save
Important:
If your FTP server exists on a CentOS 7, CloudLinux 7, or RHEL 7 server, run the following commands to allow connections through the passive port range that you set:
123firewall-cmd --permanent --zone=public --add-service=ftp
firewall-cmd --permanent --add-port=30000-50000/tcp
firewall-cmd --reload
-
Run the
/usr/local/cpanel/scripts/restartsrv_ftpserver
command to restart the FTP server. -
System updates may overwrite these configuration changes. To make these changes permanent, you must append the passive ports to the configuration file. To do this, run the following commands as the
root
user:12echo
"PassivePorts: 30000 50000"
>>
/var/cpanel/conf/proftpd/main
/usr/local/cpanel/scripts/setupftpserver
proftpd --force
For more information about how to edit your Pro-FTPd configuration, read our FTP FAQ documentation.
SolusVM and Xen
If you use SolusVM and Xen on a CloudLinux™ server, you may experience problems with passive FTP. These problems may resemble a firewall or other connection issue, even when no firewall exists.
To resolve these issues, perform the following steps:
-
Replace the
IPTABLES_MODULES=ip_conntrack_netbios_ns
line in the/etc/sysconfig/iptables-config
file on the VPS node with the following line:IPTABLES_MODULES=ipt_REJECT ipt_tos ipt_TOS ipt_LOG ip_conntrack ipt_limit ipt_multiport iptable_filter iptable_mangle ipt_TCPMSS ipt_tcpmss ipt_ttl ipt_length ipt_state iptable_nat ip_nat_ftp ipt_owner ipt_REDIRECT
-
Run the
service iptables restart
command to restart theiptables
service.