Setting Up an FTP Server (Linux)
Overview
File Transfer Protocol (FTP) is a standard protocol used to transfer files between computers over a network. It uses a client-server architecture that allows users to upload, download, rename, delete, and view files and directory structures on a remote server. FTP supports two transfer modes:
- Active mode
- The client sends commands to the server through the control connection (default port 21), and the server then actively connects to the port specified by the client through the data connection (default port 20) to transfer data.
- This mode is suitable for client network environments without firewall restrictions. However, connection failures may occur if a firewall blocks the server's active connections.
- Passive mode
- The client sends a PASV command through the control connection (port 21), and the server responds with a dynamic port (for example, 1024-65535). The client then actively connects to this port for data transfer.
- This mode is suitable for scenarios where the client is located behind a firewall or NAT device, preventing server's active connections from being blocked.
If other cloud servers on Huawei Cloud need to access the FTP server deployed on the FlexusL instance in this example over an EIP, passive mode must be used.
This section describes how to set up an FTP server on a FlexusL instance running Linux. The CentOS 7.2 64-bit is used as an example in this section.
Prerequisites
You have purchased a FlexusL instance running Linux and the instance is in the running state.
Procedure
- Remotely log in to the FlexusL instance.
- Log in to the FlexusL console.
- On the target resource card, choose
> Reset Password to reset the password as instructed. A FlexusL instance does not have an initial password. If you want to log in to a FlexusL instance, set a password for it first. If you have already set a password, skip this step.
For details, see Resetting the Password for a FlexusL Instance.
- Locate the target resource card and click Remote Login. In the displayed dialog box, click VNC Login and enter the username and password to log in to the FlexusL instance. The username is root, and the password is the one you set in the previous step.
For more login methods, see Login Modes.
- Install vsftpd. vsftpd (short for very secure FTP daemon) is an FTP server software that is widely used in Linux distributions.
- Run the following command to install vsftpd:
yum install -y vsftpd
If information similar to the following is displayed, vsftpd has been installed.

- Run the following command to enable automatic startup of FTP upon ECS startup:
systemctl enable vsftpd.service
- Run the following command to start FTP:
systemctl start vsftpd.service
- Run the following command to obtain the port running FTP:
netstat -antup | grep ftp
Information similar to the following is displayed.

- Run the following command to install vsftpd:
- Configure vsftpd.
After vsftpd is installed, anonymous FTP is enabled by default, allowing you to log in to the FTP server without requiring the login username and password. However, you are not allowed to modify or upload files. If you attempt to log in to the FTP server using the Linux OS account, your request will be rejected by vsftpd, but you are allowed to configure the username and password in vsftpd for logging in to the FTP server. To do so, perform the following operations:
- Create a user.
For example, to create user ftpadmin, run the following command:
useradd ftpadmin
- Run the following command to configure the password of user ftpadmin:
passwd ftpadmin
- Run the following command to create a file directory for the FTP server, /var/ftp/work01 is used as an example:
mkdir /var/ftp/work01
- Run the following command to change the owner of the created file directory to the local user for logging in to the FTP server:
chown -R ftpadmin:ftpadmin /var/ftp/work01
- Modify the vsftpd.conf configuration file.
- Run the following command to open the file:
vi /etc/vsftpd/vsftpd.conf
- Press i to enter insert mode.
- Modify the vsftpd.conf file.
Set FTP to active or passive mode based on site requirements. If other Huawei Cloud ECSs need to use EIPs to access the FTP server that is set up on a Huawei Cloud ECS, set FTP to passive mode.
- Parameters for configuring the active FTP mode:
#No anonymous login to the FTP server is allowed. Local users are allowed to log in to the FTP server with their local file directories specified. anonymous_enable=NO #No anonymous login to the FTP server is allowed. local_enable=YES #Local users are allowed to log in to the FTP server. local_root=/var/ftp/work01 #Specifies the file directory used by a local FTP user. #The following parameter allows login users to visit their own home directories: chroot_local_user=YES #The directory access rule applies to all users. chroot_list_enable=YES #The directory access rule does not apply to exclusive users. chroot_list_file=/etc/vsftpd/chroot_list #Specifies exclusive users. allow_writeable_chroot=YES
- The passive FTP mode requires not only all the parameters configured for the active FTP mode, but also include the following parameter settings:
#The public IP address of the FTP server and the range of accessible ports must also be configured. listen=YES listen_ipv6=NO pasv_address=xx.xx.xx.xx #Public IP address of the FTP server pasv_min_port=3000 #Minimum port number in passive FTP mode pasv_max_port=3100 #Maximum port number in passive FTP mode
- Parameters for configuring the active FTP mode:
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Create the chroot_list file in /etc/vsftpd/.
touch chroot_list
The chroot_list file contains exclusive users to whom the home directory access rules do not apply. To allow a user to access non-home directories, add the username to this file. If there is no exclusive user, the chroot_list file can be left blank, but the file must be available.
- Run the following command to open the file:
- Run the following command to restart vsftpd to apply the setting:
systemctl restart vsftpd.service
- Create a user.
- Configure security groups.
After the FTP site is set up, add inbound rules to the security group of the FlexusL instance to allow access to the FTP port. For details, see Configuring Security Group Rules for a FlexusL Instance. For details about the ports to be allowed, see Table 1.
- If the active mode is used, you must allow the port (port 21 by default) used by the FTP site in the security group.
- If the passive mode is used, you must allow the ports (port 21 by default) used by the FTP site and all ports within the range specified by pasv_min_port and pasv_max_port in the vsftpd.conf file (ports 3000–3100 in this example) in the security group.
Table 1 Security group rules Priority
Action
Type
Protocol & Port
Source
1
Allow
IPv4
TCP (Custom ports): 20-21
0.0.0.0/0
1
Allow
IPv4
TCP (Custom ports): ports within 1024-65535 (for example, 3000-3100)
0.0.0.0/0
If the source of an inbound rule is set to 0.0.0.0/0 or ::/0, then all external IP addresses are either allowed or denied to access your instances, depending on if the action is Allow or Deny. If the access is allowed, exposing ports to the public network poses security risks, such as network intrusions, service disruptions, data leaks, and ransomware attacks. It is recommended that you set security group rules to allow access only from trusted IP addresses, such as the IP address of the client that needs to access the FTP server in the next step.
- Test the client.
Open a client computer, which can be a local Windows computer or another Windows cloud server, and enter ftp://<FTP-server-public-IP-address>:<FTP-port> in the path bar. In this example, <FTP-server-public-IP-address> is the EIP of the FlexusL instance. If you do not specify the FTP port, port 21 is used by default.
If a dialog box prompting for a username and password appears, the configuration is successful. After entering the correct username and password, you can perform operations on FTP files based on your assigned permissions.
- If active FTP mode is selected, use this method to configure the Internet Explorer browser. Otherwise, the FTP folder will be inaccessible. To configure the Internet Explorer browser, choose Tools > Internet Options > Advanced, select Enable FTP folder view, and deselect Use Passive FTP.
- If an error occurs when you use a browser to access the FTP server, clear the browser caches and try again.
You can also download FileZilla from the client to transfer files.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot