What is FTP?
FTP (File Transfer Protocol) is a network protocol used to transfer data between a client and a server over the Internet or a local network. FTP allows users to upload (upload) and download (download) files while also supporting remote file management, making it easy to share and store data.
FTP operates using the client-servermodel, in which the FTPserver is responsible for storing files, while the client connects to the server to transfer or manage data.

FTP uses two connections: FTP Control (Port 21) and FTP Data (Port 20):
- FTP Control: remains open whenever data or commands are being sent
- FTP Data: opens only when actual data is exchanged
Process:
- The FTP client opens a control connection to the FTP server (Port 21) to transmit commands.
- The client sends a username and password for authentication; the server responds by accepting or rejecting the request.
- The client sends a command specifying the file name and data type; the server returns a response code indicating acceptance or rejection.
- When ready, both parties establish a TCP connection on Port 20 to transfer data in either ASCII or binary format.
- After the data transfer is complete, the Data Connection (Port 20) closes, while the Control Connection (Port 21) remains open for additional data transfers or to terminate the session.
Active Data Connection and Passive Data Connection.

Passive FTP mode
- The client opens the Data and Control ports.
- Control Connection: The client opens an arbitrary port and sends a packet to the server on Port 21; the server responds using the three-way handshake process.
- Data Connection: The Client sends the PASV command over the Control Connection and communicates with the Server through a High Port.
- The FTP Client establishes both connections and receives data without using Port 20.
- The username and password are sent in plaintext, making them easy to intercept with Wireshark.
- Observation: Passive mode benefits the Client, but it opens multiple high ports (>1023) on the Server, creating security risks. The solution is to limit the port range on the Server to improve control and mitigate risks.
FTP Active mode
Typically, the FTP Server initiates the data request, but this may be blocked if the Client's Firewall blocks the Server port in use.
- If the Firewall/Router blocks SYN packets from the Server's Port 20, FTP can execute commands only over the Control Connection and cannot transmit data.
- Control Connection: Same as Passive mode.
- Data Connection: The Server uses Port 20, while the Client uses a High Port.
- The FTP Client creates the Control Connection, while the FTP Server creates the Data Connection and actively sends the data.
Installing and configuring an FTP Server with ProFTPD.
Step 1: Install ProFTPD
- To install ProFTPD on Ubuntu, SSH into the server and execute the following commands.
sudo apt-get update sudo apt-get install -y proftpd

Step 2: Check the ProFTPD service
After the installation completes successfully, check the status of the ProFTPD service:
sudo systemctl status proftpd

If the service is not running, you can start ProFTPD:
sudo systemctl start proftpd
To configure the service to start automatically with the system, run the following command:
sudo systemctl enable proftpd
Step 3: Configure ProFTPD
The main ProFTPD configuration file is located at /etc/proftpd/proftpd.conf. You can edit this file using a text editor such as nano or vim:
sudo nano /etc/proftpd/proftpd.conf
Below are some basic configuration settings:
-
Change the FTP server name: Find the line
ServerNameand change it as desired:
ServerName "My FTP Server"
- Allow or deny anonymous users (To prevent anonymous users from accessing the server, find and modify the following):
<Anonymous ~ftp> User ftp Group ftp # Comment out the following lines: # UserAlias anonymous ftp # <Directory *> # <Limit WRITE> # DenyAll # </Limit> # </Directory> </Anonymous>
- Configure the user and group for FTP:
User ftp Group ftp
- Configure Passive Mode (required if your server is behind a firewall):
PassivePorts 60000 65535 MasqueradeAddress 1.2.3.4 # Thay 1.2.3.4 bằng địa chỉ IP của bạn.
Step 4: Create an FTP User
Create a new FTP user:
sudo useradd -m ftpuser sudo passwd ftpuser
Then, ensure that the user's home directory has the appropriate access permissions:
sudo chown -R ftpuser:ftpuser /home/ftpuser

Step 5: Check the configuration
After completing the configuration, you should verify the validity of the configuration file using the following command:
sudo proftpd --configtest
If there are no errors, restart the service:
sudo systemctl restart proftpd

Step 6: Check the FTP Server
Usage ftp To test the connection to the FTP Server:

Using FTP via the CLI
-
FTP login: Use the command
ftp <hostname>. -
List files: Command
lsTo view the list of files in the directory. -
Change directory: Use the command
cd <thư_mục>To navigate to another directory. -
Download a file: Use the command
lcd <local_directory>To set the download location before usingget <tên_file>. -
Upload a file: Use the command
put <tên_file>To upload a file to the server. -
Delete a file: Command
delete <tên_file>to delete a file. -
End the FTP session : Type
byeorquitto end the FTP session.
In addition, you can log in and use FTP with FileZilla or a web browser.
FTP security
-
FTPtransmits data insecurely when login credentials are exposed in plaintext, making them vulnerable to attack. To address this, security can be added through TLS/SSL (FTPS), or the SFTPprotocol can be used.
-
FTPS adds TLS/SSL encryption to traditional FTP, helping protect login credentials and data during transmission. However, FTPSrequires multiple ports to be opened, making firewall configuration more difficult.
-
SFTP, which is based on the SSH protocol, provides more comprehensive security by encrypting all information and requiring only one port, making deployment and management easier.
-
To further enhance security, you can apply two-factor authentication (2FA) or key-pair authentication Combined with a username and password, this adds a critical layer of defense against brute-force attacks and phishing. These mechanisms not only protect the login process but also ensure data integrity and confidentiality throughout transmission.
References
ProFTPD Installation Guide:
- ProFTPD Documentation – Detailed documentation on installing and configuring ProFTPD.
Information about SFTP and FTPS:
- Difference Between SFTP and FTPS – An explanation of the differences between SFTP and FTPS.
FTP Security Documentation:
- How to Secure an FTP or SFTP Server – A guide to security measures for FTP.