FTP (File Transfer Protocol) is a standard network protocol used to transfer files to or from a remote network.
In this tutorial, we will show you how to use the Linux ftp command through practical examples.
In most cases, it is easiest to use a GUI FTP client software to connect to a remote server and download or upload files. However, there are times when you have to work on a server without a GUI. ranking
ftp Very useful when the machine is command line only and you want to transfer files via FTP to or from a remote server.
It is recommended to open the console of your Linux distribution to follow the guide on this page to better understand how it works FTP command on Linux stations.
We also recommend that you test any online tutorials or guides on a virtual machine (vmware or virtualbox) before deploying to a production server, so you don’t mess with an active OS when something goes wrong.
You can learn how to install VMware on Ubuntu and CentOS. To learn how to install VirtualBox, there are guides for Ubuntu, Fedora, and CentOS
Please note that when any data is transmitted via FTP, the communication between you and the server is not encrypted. To transfer data more securely, use the SCP command.
To be able to transfer files, you must have at least permission read (Read) in the source file and Type (Write) permission on the destination system.
When transferring large files, it is recommended to run the ftp command within a tmux screen or session.
The directory where you run the command
ftp It is a local business directory.
Create an FTP connection
- To open an ftp connection to a remote system, use the ftp command followed by the remote server’s IP address or domain name:
- If the connection is established, a confirmation message will be displayed and you will be asked to enter your FTP username, in this case your FTP username is
220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 220-You are user number 1 of 50 allowed. 220-Local time is now 21:35. Server port: 21. 220-This is a private system - No anonymous login 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 15 minutes of inactivity. Name (192.168.122.37:localuser): linux
You may see different confirmation messages depending on which FTP service is running on the remote server.
- After entering your username, you will be asked to type in your password:
- If the password is correct, then server controller It will display a confirmation message and prompt
230 OK. Current restricted directory is / Remote system type is UNIX. Using binary mode to transfer files. ftp>
If the FTP server you are accessing accepts anonymous ftp accounts, and you want to log in as an anonymous user, use
anonymousAs your username and your email address as your password.
Common FTP Commands
Many FTP commands are the same or identical to the commands you type at the Linux shell prompt.
Here are some of the most popular FTP commands
?– View a list of all available FTP commands.
cd– o change directory To change the directory on the remote machine.
lcd– o Local change guide To change the directory on the local machine
lsls command to see a list of file and directory names in the current remote directory.
mkdirCreate a new directory within the current remote directory.
pwdPrint the current working directory on the remote server.
delete– Delete files in the current remote directory.
rmdir– Delete the directory in the current remote directory.
getCopy or download a single file remotely to a local device.
mget– Copy or download multiple files remotely to the local device
put– Upload a single file from the local machine to the remote machine.
mput– Upload multiple files from the local machine to the remote machine.
How to download files with FTP commands
Once logged in, the current working directory is the user’s home directory on the remote machine.
When downloading a file with the command
ftp the file will be downloaded to the directory where you typed the ftp command (on the local machine).
If you want to download the file to another directory on the local machine, redirect the download with the command
Suppose we want to download a file to a directory
To download a single file from a remote server, use the command
get. For example to download a file named
backup.zip Use the following command:
The output will look like this:
200 PORT command successful 150-Connecting to port 60609 150 6516.9 kbytes to download 226-File successfully transferred 226 2.356 seconds (measured here), 2.70 Mbytes per second 6673256 bytes received in 2.55 seconds (2.49 Mbytes/s)
To download multiple files at once, use the command
mget. You can provide a list of individual file names or use wildcards.
mget backup1.zip backup2.zip
When downloading multiple files, you will be asked to confirm each file.
mget backup1.zip? y 200 PORT command successful 150 Connecting to port 52231 226-File successfully transferred 226 0.000 seconds (measured here), 31.51 Kbytes per second 14 bytes received in 0.00058 seconds (23.6 kbytes/s) mget backup2.zip? y 200 PORT command successful 150-Connecting to port 59179 150 7.2 kbytes to download 226-File successfully transferred 226 0.000 seconds (measured here), 16.68 Mbytes per second 7415 bytes received in 0.011 seconds (661 kbytes/s)
When you have finished downloading files from the remote FTP server, close the connection with the command
221-Goodbye. You uploaded 0 and downloaded 6544 kbytes. 221 Logout.
How to upload files with FTP commands
To upload files from a local directory to a remote FTP server, use the command
The output will look like this:
200 PORT command successful 150 Connecting to port 34583 226-File successfully transferred 226 0.849 seconds (measured here), 111.48 Kbytes per second 96936 bytes sent in 0.421 seconds (225 kbytes/s)
If you want to load a file that is not in the current working directory, use the absolute path of the file.
To upload multiple files from a local directory to a remote FTP server, use the command
mput image1.jpg image2.jpg
mput image1.jpg? y 200 PORT command successful 150 Connecting to port 41075 226-File successfully transferred 226 1.439 seconds (measured here), 102.89 Kbytes per second 151586 bytes sent in 1.07 seconds (138 kbytes/s) mput image2.jpg? y 200 PORT command successful 150 Connecting to port 40759 226-File successfully transferred 226 1.727 seconds (measured here), 111.75 Kbytes per second 197565 bytes sent in 1.39 seconds (138 kbytes/s)
When uploading multiple files, you will be prompted to confirm each file you want to upload.
After you have finished uploading files to the remote FTP server, close the connection with the command
The ftp command in Linux Terminal is very useful when you are working in a server environment that does not have a graphical user interface. In this tutorial, you learned how to use the ftp command to download and upload files to a remote FTP server.