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 (Ubuntu 22.04)
Copy page
Download PDF
Setting up FTP sites (Ubuntu 22.04)
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 Ubuntu 22.04 instance.​
Prerequisites​
  • The ECS instance status is Running.​
Software version​
  • Linux operating system: This topic uses Ubuntu 22.04 as an example.​
  • Client operating system: This topic uses macOS Sequoia 15.6.1 as an example.​
  • vsftpd: This topic uses vsftpd 3.0.2 as an example.​
Procedure​
Step 1: Install vsftpd​
  1. Log in to the ECS console.​
  1. Execute the following commands to install vsftpd.​
  • ​
    sudo apt-get update​
    sudo apt-get -y install 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 vsftpd​
  1. Execute the following command to back up the vsftpd configuration file.​
  • ​
    sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak​
    ​
  1. Modify the vsftpd configuration file.​
  1. Execute the following command to open the vsftpd configuration file.​
  • ​
    sudo vim /etc/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.​
  • ​
    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 a chroot_list file, and add the list of exception usernames to the file.​
tip​
Users in an exception list are not restricted to their home directories and can access other directories.​
  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.​
  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 3: Configure user directory​
  1. After you install vsftpd, a default passwordless user named ftp is created. Execute the following command to modify the password.​
  • ​
    sudo passwd ftp​
    ​
  • If the following output is displayed, the login password for user ftp is modified.​
  • ​​​
  1. Execute the following command to ensure that the shell of user ftp is included in the /etc/shells file.​
  • ​
    SHELL_TO_CHECK=$(getent passwd ftp | cut -d: -f7) && (grep -q "^$SHELL_TO_CHECK$" /etc/shells || echo "$SHELL_TO_CHECK" >> /etc/shells)​
    ​
  1. Execute the following command to add the user ftp to the vsftpd list of users allowed to log in.​
  • ​
    echo "ftp" | sudo tee -a /etc/vsftpd.userlist​
    ​
  1. Execute the following command to create the FTP file directory.​
  • ​
    sudo mkdir /home/ftp​
    ​
  1. Execute the following command to grant permissions for the FTP file directory.​
tip​
In the example provided in this topic, read, write, and full control permissions on the folder are granted. Modify the corresponding permissions as needed.​
  • ​
    sudo chmod 777 /home/ftp​
    ​
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:27