Skip to content

πŸ“‚ FTP Tutorial: Installing, Configuring, and Using FTP on Linux

Welcome to this tutorial on FTP (File Transfer Protocol). In this guide, we will cover the basics of FTP, how to install and configure an FTP server on Linux, and how to transfer files between a Linux client and server.

πŸ“‘ Table of Contents

  1. πŸ“„ What is FTP?
  2. πŸ” What is a Protocol?
  3. πŸ”’ What is the Default FTP Port?
  4. πŸ› οΈ Installing and Configuring FTP on a Remote Server and Client
  5. πŸ“ Examples: Moving Files Between Linux Client and Server

πŸ“„ What is FTP?

FTP (File Transfer Protocol) is a standard network protocol used to transfer files between a client and a server over a TCP/IP network, such as the internet or a local network. FTP allows users to:

  • πŸ“₯ Upload files
  • πŸ“€ Download files
  • πŸ“ Rename files
  • ❌ Delete files
  • πŸ“‚ Move files on a server

FTP operates in two modes:

  • Active Mode πŸ“Ά: The client opens a port and waits for the server to connect.
  • Passive Mode 🌐: The server opens a port and waits for the client to connect.

πŸ” What is a Protocol?

A Protocol is a set of rules or standards that dictate how data is transmitted and received over a network. Protocols define the methods and formats for communication between devices, ensuring that data is sent, received, and interpreted correctly. Examples of protocols include:

  • HTTP πŸ•ΈοΈ: HyperText Transfer Protocol
  • FTP πŸ“‚: File Transfer Protocol
  • TCP/IP 🌐: Transmission Control Protocol/Internet Protocol
  • SMTP πŸ“§: Simple Mail Transfer Protocol

πŸ”’ What is the Default FTP Port?

The Default FTP Port 21 is the port number assigned to the control connection in the FTP protocol. When an FTP client initiates a connection to an FTP server, it connects to the server on port 21 to send commands. Data transfers typically occur over a separate port (usually port 20 or a dynamically assigned port in passive mode).

πŸ› οΈ Installing and Configuring FTP on a Remote Server and Client

πŸ“‘ On the FTP Server:

  1. Install FTP Server Software:

  2. On a Debian/Ubuntu server:

    sudo apt update
    sudo apt install vsftpd
    

  3. On a CentOS/RHEL server:

    sudo yum install vsftpd
    

  4. Configure the FTP Server:

  5. Open the configuration file:

    sudo nano /etc/vsftpd.conf
    

  6. Modify the following settings as needed:
    • Ensure anonymous_enable=NO (to disable anonymous login).
    • Set local_enable=YES (to enable local user login).
    • Set write_enable=YES (to allow file uploads).
    • Enable passive mode by adding the following:
      pasv_enable=YES
      pasv_min_port=10000
      pasv_max_port=10100
      
    • Enable local time by adding:
      use_localtime=YES
      
  7. Save and close the file.

  8. Start and Enable the FTP Server:

sudo systemctl start vsftpd
sudo systemctl enable vsftpd
  1. Allow FTP through the Firewall:
  2. On Debian/Ubuntu:
    sudo ufw allow 21/tcp
    sudo ufw allow 10000:10100/tcp
    
  3. On CentOS/RHEL:
    sudo firewall-cmd --permanent --add-port=21/tcp
    sudo firewall-cmd --permanent --add-port=10000-10100/tcp
    sudo firewall-cmd --reload
    

πŸ’» On the FTP Client:

  1. Install FTP Client Software:

  2. On a Debian/Ubuntu client:

    sudo apt install ftp
    

  3. On a CentOS/RHEL client:

    sudo yum install ftp
    

  4. Connect to the FTP Server:

  5. Open a terminal and connect using the FTP command:
    ftp your_server_ip_or_hostname
    
  6. Enter the username and password when prompted.

πŸ“ Examples: Moving Files Between Linux Client and Server

πŸ“€ Upload Files

To upload a file from your local machine to the server:

ftp your_server_ip
# Login with your username and password
put /path/to/local/file /path/to/remote/directory/

πŸ“₯ Download Files

To download a file from the server to your local machine:

ftp your_server_ip
# Login with your username and password
get /path/to/remote/file /path/to/local/directory/

πŸ“ Rename Files

To rename a file on the server:

ftp your_server_ip
# Login with your username and password
rename oldfile.txt newfile.txt

❌ Delete Files

To delete a file on the server:

ftp your_server_ip
# Login with your username and password
delete file_to_delete.txt

πŸ“‚ Move Files on a Server

To move a file from one directory to another on the server:

ftp your_server_ip
# Login with your username and password
rename /current/path/file.txt /new/path/file.txt

This tutorial provides an overview of FTP, its installation, configuration, and basic usage for file transfers between Linux systems. Happy file transferring! πŸ“‚πŸš€