Linux ftp Command
On Linux systems,ftp the command is a command-line tool for interacting with FTP servers.
Pass ftp With the 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 for transferring files 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 is still widely used today in areas such as file sharing and website maintenance.
In FTP, there are two main roles:
- Client Side: the party that initiates a 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 the actual file transfer.
Installation ftp Client Side
In most Linux distributions,ftp the client is usually pre-installed. If not, you can install it with the following command:
Debian/Ubuntu System:
sudo apt-get install ftp
CentOS/RHEL System:
sudo yum install ftp
Syntax
ftp [-dignv][主机名称或IP地址]
Parameters:
- -d Display the command execution process in detail, making it easier to troubleshoot or analyze program execution.
- -i Disable interactive mode and do not ask any questions.
- -g Disable support for expanding special characters in local host file names.
- -n Do not use automatic login.
- -v Display the command execution process.
Example
1. Connect to the FTP server
For example, connect to ftp.example.com:
ftp ftp.example.com
After a successful connection, you will be prompted for a user name and password. If the FTP server allows anonymous access, you can use anonymous as the user name and your email address as the password.
2. Common FTP commands
Once connected 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 a file from the remote server to the local computer: get remote_file local_file.put: upload a local file 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: remove a directory on the remote server: rmdir directory_namebyeorquit: disconnect from the FTP server and exit theftpclient.
Example operations
Suppose you connect to ftp.example.com, and want to download a file named example.txt to the directory on the local computer ~/downloads , and follow these steps:
- Connect to the FTP server:
ftp ftp.example.com
Enter your user name and password.
- Switch to the target directory on the remote server (if needed):
cd /path/to/remote/directory
- Switch to the target directory on the local computer:
lcd ~/downloads
4. Download the file:
get example.txt
- Disconnect and exit:
bye
Security considerations
The FTP protocol itself is not encrypted, which means user names, passwords, and file contents may be intercepted during transmission. To improve security, the following alternatives are recommended:
- SFTP(SSH File Transfer Protocol): a secure file transfer protocol based on SSH.
- FTPS(FTP Secure): FTP with SSL/TLS encryption added.
Linux Command Reference