You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
Building FTP site
Setting up FTP sites (CentOS 7.6)
Copy page
Download PDF
Setting up FTP sites (CentOS 7.6)
FTP is an application-layer protocol used for file transfer between a client and a server over a computer network. Typically, it operates on two ports: 20 and 21. This topic describes how to set up an FTP site on a CentOS 7.6 instance.​
Prerequisites​
  • The ECS instance status is Running.​
Software version​
  • Linux operating system: In the example provided by this topic, CentOS 7.6 is used.​
  • Client operating system: In the example provided by this topic, macOS Sequoia 15.6.1 is used.​
  • vsftpd: This topic uses vsftpd 3.0.2 as an example.​
Procedure​
Step 1: Install vsftpd​
  1. Log in to ECS console.​
  1. Execute the following command to install vsftpd.​
  • ​
    yum install -y vsftpd​
    ​
  1. Execute the following command to specify that the vsftpd automatically starts upon instance startup.​
  • ​
    systemctl enable vsftpd​
    ​
  1. Execute the following command to start the FTP service.​
  • ​
    systemctl start vsftpd​
    ​
  1. Execute the following command to check whether the service is started.​
  • ​
    netstat -antup | grep vsftpd​
    ​
  • If the following output is displayed, the vsftpd service is started.​
  • ​​​
tip​
vsftpd allows anonymous access by default. The default FTP server path for anonymous users is /var/ftp/pub. Anonymous users only have view permissions—they cannot create, delete, or modify files or directories.​
Step 2: Configure user directory​
  1. Execute the following command to create a Linux user for the FTP service. In the example provided in this topic, the user "ftptest" is created.​
  • ​
    sudo adduser ftptest​
    ​
  1. Execute the following command to set a password for user "ftptest".​
  • ​
    sudo passwd ftptest​
    ​
tip​
Enter the password as prompted, and press Enter to confirm the setting. The password is not displayed by default.​
  1. Execute the following command to create the FTP service directory. This topic uses /home/ftp as an example.​
  • ​
    sudo mkdir /home/ftp​
    ​
  1. Execute the following command to specify the owner of the /home/ftp directory as "ftptest".​
  • ​
    sudo chown -R ftptest:ftptest /home/ftp​
    ​
Step 3: Configure vsftpd​
  1. Execute the following command to back up the vsftpd configuration file.​
  • ​
    sudo cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak​
    ​
  1. Modify the vsftpd configuration file.​
  1. Execute the following command to open the vsftpd configuration file.​
  • ​
    sudo vim /etc/vsftpd/vsftpd.conf​
    ​
  1. Press the i key to enter edit mode. Enable IPv4 socket listening, and disable IPv6 socket listening.​
  • ​
    listen=YES​
    listen_ipv6=NO​
    ​
  1. Modify the FTP access permissions to allow only local users to access FTP and disable anonymous access.​
  • ​
    anonymous_enable=NO​
    local_enable=YES​
    ​
  1. Modify the following configuration to enable file uploads.​
  • ​
    write_enable=YES​
    ​
  1. Remove the comment symbol # at the beginning of the following configuration lines. This allows you to restrict FTP user directory access using chroot jails and configure which files FTP service users can access.​
  • ​
    chroot_local_user=YES​
    chroot_list_enable=YES​
    chroot_list_file=/etc/vsftpd/chroot_list​
    ​
  1. Add FTP service directory configuration and enable write permissions for users in the mounted chroot (root directory change) environment.​
tip​
Replace /home/ftp with the actual file directory used by the FTP service.​
  • ​
    local_root=/home/ftp​
    allow_writeable_chroot=YES​
    ​
  1. Add the following configuration as needed to set FTP to active mode or passive mode.​
tip​
Due to firewall settings on most clients and other factors, the active mode may cause issues. We recommend using passive mode to set up an FTP service.​
  • Active mode​
  • ​
    port_enable=YES​
    ​
  • Passive mode​
tip​
Replace <PUBLIC_IP> with the actual public IP address of the server hosting the FTP site.​
  • ​
    pasv_enable=YES​
    pasv_min_port=35000​
    pasv_max_port=40000​
    pasv_address=<PUBLIC_IP>​
    ​
  1. Press the esc key to exit edit mode, enter :wq, and press the Enter key to save the changes and exit the configuration file.​
  1. Create the chroot_list file.​
  1. Execute the following command to create the chroot_list file.​
  • ​
    sudo vim /etc/vsftpd/chroot_list​
    ​
  1. Press i to enter edit mode and enter the exception user list.​
tip​
Users in an exception list are not restricted to their home directories and can access other directories.​
  1. Press Esc to exit the edit mode, enter :wq, and then press Enter to save and exit the file.​
  1. Execute the following command to restart vsftpd for the configuration to take effect.​
  • ​
    sudo systemctl restart vsftpd​
    ​
Step 4: Configure security group​
After the FTP site is set up, add rules to the inbound direction of the instance security group and allow the following FTP ports. For detailed steps, refer to Changing security group rules.​
​
FTP usage mode​
Direction​
Protocol type​
Port range​
Source address​
Active mode​
Inbound​
TCP​
20/21​
0.0.0.0/0​
Passive mode​
Inbound​
TCP​
Port 21, and all ports between the values of parameters pasv_min_port and pasv_max_port, which are defined in the /etc/vsftpd/vsftpd.conf configuration file.​
tip​
To adjust the passive mode port range, refer to configuration recommendations. This topic uses the range 35000-40000 as an example.​
0.0.0.0/0​
​
Step 5: Client test​
You can verify the FTP service using FTP client software, a browser, a file explorer, or other tools. This topic uses MacOS Finder as an example.​
  1. Open Finder and select "Go > Connect to Server" in the top menu bar.​
  1. Enter ftp://ECS instance EIP:21 and click the "Connect" button.​
  1. In the pop-up login window, confirm the FTP server information and click the "Connect" button.​
  1. Enter the FTP username and password that have been set, and then click "Connect". After the connection succeeds, you can view the files in the specified directory on the FTP server.​
warning​
Since macOS "Finder" does not support uploading files to an FTP server, you can download third-party software like FileZilla to transfer files.​
Last updated: 2026.06.18 17:48:26