Learn about FTP/FTPS/SFTP file transfer protocols in one article

2023.11.20

Learn about FTP/FTPS/SFTP file transfer protocols in one article

To use SFTP for file transfer, you need an SFTP client software (such as FileZilla, WinSCP, etc.) and an SFTP server. When connecting to an SFTP server, you need to provide the server's address, port number, username, and password (or use an SSH key for authentication).

FTP introduction

FTP (File Transfer Protocol) is a protocol used for file transfer on a computer network. It allows users to transfer files from one computer to another over the network. FTP uses a client-server model, where the client connects to the server through FTP client software and authenticates using a username and password.

FTP supports a variety of operations, including uploading files to the server, downloading files from the server, deleting files on the server, renaming files, etc. Users can perform these operations through FTP client software or use FTP commands through the command line interface.

Example command to upload files using FTP:

  1. Connect to FTP server:
ftp <服务器地址>
  • 1.
  1. Enter username and password to log in:
<用户名>
<密码>
  • 1.
  • 2.

For example:

myusername
mypassword
  • 1.
  • 2.
  1. Switch to the directory where you want to upload the file:
cd <目录路径>
  • 1.

For example:

cd /path/to/upload/directory
  • 1.
  1. Set the transfer mode to binary mode:
binary
  • 1.
  1. Start uploading files:
put <本地文件路径>
  • 1.

For example:

put /path/to/local/file.txt
  • 1.
  1. After the upload is complete, disconnect from the FTP server:
bye
  • 1.

How FTP works

The FTP protocol is based on the client-server model, where the client establishes a connection with the server through FTP client software and sends and receives files through the connection.

  1. Establish a connection: The client uses FTP client software to establish a connection with the server. Usually the default port number 21 of the TCP protocol is used to connect.
  2. Authentication: After the connection is established, the client needs to provide a username and password for authentication. These credentials are used to verify that the client has permission to access files on the server.
  3. Directory Navigation: Once authentication is successful, the client can use FTP commands to navigate the directory structure on the server. Commonly used commands include CD (change directory), LS (list directory contents), etc.
  4. File Transfer: Clients can use FTP commands to upload and download files. When uploading a file, the client sends the local file to the server; when downloading the file, the client obtains the file from the server.
  5. Data transfer mode: FTP supports two data transfer modes: active mode and passive mode. In active mode, the server actively connects to the client's data port for data transmission; in passive mode, the client actively connects to the server's data port for data transmission.
  6. Disconnect: When the file transfer is complete or the connection is no longer needed, the client can disconnect from the server by sending the QUIT command.

The working principle of FTP is to realize the function of file transfer on the computer network through steps such as connection establishment, authentication, directory navigation and file transfer.

Differences in FTP data transfer modes

In FTP, there are two different data transmission modes: Active Mode and Passive Mode.

  1. Active Mode: In active mode, the client first establishes a control connection (Control Connection) to the server's FTP control port (default is 21). When data needs to be transmitted, the client will randomly select a port (called N) and notify the server, and then the server will tell the client to use a new data connection (Data Connection) to transmit data through the control connection. In active mode, the data connection is actively initiated by the server, and the client acts as the data receiver.
  2. Passive Mode: In passive mode, the client first establishes an FTP control port that controls the connection to the server. When data needs to be transmitted, the server will randomly select a port (called N) and notify the client, and then the client will tell the server to use a new data connection to transmit data through the control connection. In passive mode, the data connection is actively initiated by the client, and the server acts as the data receiver.

The difference between active mode and passive mode is how the data connection is established. In active mode, the server actively initiates a data connection, while in passive mode, the client actively initiates a data connection. The choice between these two modes depends on the network environment and firewall configuration. In some cases, active mode may be restricted by firewalls, while passive mode can better adapt to various network environments. Therefore, when using FTP for data transfer, you need to choose the appropriate mode according to the specific situation.

Introduction to FTPS

FTPS (File Transfer Protocol Secure) is a secure file transfer protocol that adds an SSL/TLS encryption layer to FTP (File Transfer Protocol) to protect the security of data transmission.

Encrypted file transfer between client and server is possible using FTPS. It uses SSL/TLS protocol to encrypt and authenticate data, ensuring data security and integrity during transmission.

FTPS can transmit in two modes: explicit mode and implicit mode. In explicit mode, communication between client and server is always clear text, but is encrypted using SSL/TLS when establishing a data connection. In implicit mode, the entire communication process is encrypted.

Using FTPS can effectively protect sensitive data during file transfer and prevent data from being stolen or tampered with. It is widely used in scenarios where data security needs to be protected, such as website file uploads, backups, and remote file management.

Introduction to SFTP

SFTP (Secure File Transfer Protocol) is a secure file transfer protocol used to securely transfer files over a computer network. It performs encryption and authentication via SSH (Secure Shell) protocol, ensuring confidentiality and integrity of file transfers.

Using SFTP you can achieve the following functions:

  • File Upload and Download: Files can be uploaded from the local computer to a remote server, or downloaded from a remote server to the local computer.
  • File and directory management: Can create, delete, rename and move files and directories.
  • Permission control: You can set permissions on files and directories to restrict users' access to and operations on files.
  • Resumable transfer: If the file transfer process is interrupted, SFTP can resume the transfer and continue the transfer from where it was interrupted.

To use SFTP for file transfer, you need an SFTP client software (such as FileZilla, WinSCP, etc.) and an SFTP server. When connecting to an SFTP server, you need to provide the server's address, port number, username, and password (or use an SSH key for authentication).

Example command to upload files using SFTP:

sftp username@hostname
put local_file remote_file
  • 1.
  • 2.

Among them, username is the user name of the remote server, hostname is the address of the remote server, local_file is the file path on the local computer, and remote_file is the path to save the file on the remote server.

Common tools for FTP

  1. FileZilla: FileZilla is a free, open source FTP client that supports Windows, Mac and Linux operating systems. It has an intuitive user interface that makes it easy to manage and transfer files.
  2. WinSCP: WinSCP is a free and open source SFTP, SCP and FTP client for the Windows platform. It provides a graphical interface and a command line interface, supporting functions such as file transfer, file management, and remote execution of commands.
  3. CuteFTP: CuteFTP is a powerful commercial FTP client that supports Windows operating systems. It has an intuitive user interface and rich features such as file transfer, folder synchronization, file editing, etc.
  4. Cyberduck: Cyberduck is a free FTP and cloud storage client that supports Windows and Mac operating systems. It supports multiple protocols, including FTP, SFTP, WebDAV, Amazon S3, etc., making it easy to manage and transfer files.

These tools provide simple and easy-to-use interfaces and rich functions, which can meet the needs of most FTP operations.