Linux ftp command

Linux 命令大全Linux Command Reference

In the Linux system,ftpthe command is a command-line tool used to interact with FTP servers.

Throughftpthe command, users can connect to a remote FTP server, upload or download files, and perform other file management operations.

What is FTP?

FTP (File Transfer Protocol) is a standard protocol used for file transfer over a network. It allows users to upload and download files between different computers.

FTP is one of the earliest protocols used on the Internet, and it is still widely used in fields such as file sharing and website maintenance.

In FTP, there are two main roles:

  • Client: the party that initiates the file transfer request.
  • Server: the party that responds to client requests and provides files.

FTP uses two ports for communication:

  • Control connection(port 21): used to send commands and receive responses.
  • Data connection(port 20): used for actual file transfer.

InstallationftpClient

In most Linux distributions,ftpthe client is usually pre-installed. If it is not installed, you can use the following command to install it:

Debian/UbuntuSystem:

sudo apt-get install ftp

CentOS/RHELSystem:

sudo yum install ftp

Syntax

ftp [-dignv][主机名称或IP地址]

Parameters:

  • -d Display the command execution process in detail, for troubleshooting or analyzing how the program executes.
  • -i Turn off interactive mode and do not ask any questions.
  • -g Disable the expansion feature that supports special characters in local host file names.
  • -n Do not use automatic login.
  • -v Display the command execution process.

Examples

1. Connect to an FTP server

For example, connect toftp.example.com:

ftp ftp.example.com

After a successful connection, the system will prompt you to enter a username and password. If the FTP server allows anonymous access, you can useanonymousas the username and use your email address as the password.

2. Common FTP commands

Once you successfully connect to the FTP server, you can use the following common commands for file operations:

  • ls: list files and directories on the remote server.
  • cd: change the current directory on the remote server.
  • lcd: change the current directory on the local computer.
  • get: download files from the remote server to the local computer:get remote_file local_file。
  • put: upload local files to the remote server:put local_file remote_file。
  • mget: download multiple files:mget file1 file2 file3。
  • mput: upload multiple files:mput file1 file2 file3。
  • delete: delete a file on the remote server: delete remote_file.
  • mkdir: create a directory on the remote server:mkdir directory_name。
  • rmdir: delete a directory on the remote server:rmdir directory_name
  • byeorquit: disconnect from the FTP server and exitftpclient.

Example operations

Suppose you connect toftp.example.com, and want to download a file namedexample.txtto the local computer's~/downloadsdirectory, you can follow these steps:

1. Connect to the FTP server:

ftp ftp.example.com

Enter the username and password.

2. Switch to the target directory on the remote server (if needed):

cd /path/to/remote/directory

3. Switch to the target directory on the local computer:

lcd ~/downloads

4. Download the file:

get example.txt

5. Disconnect and exit:

bye

Security considerations

The FTP protocol itself is unencrypted, which means usernames, passwords, and file contents may be eavesdropped during transmission. To improve security, the following alternatives are recommended:

  • SFTPSFTP (SSH File Transfer Protocol): a secure file transfer protocol based on SSH.
  • FTPSFTPS (FTP Secure): adds SSL/TLS encryption on the basis of FTP.

Linux 命令大全Linux Command Reference

Other extensions