How to Use Linux FTP Command to Transfer Files
6 min read
FTP (File Transfer Protocol) is a standard network protocol used to transfer files to and from a remote network.
In this tutorial, we will show you how to use the Linux
ftp command through practical examples.
In most cases, you will use a desktop FTP client to connect to the remote server and download or upload files. However, the
ftp command is useful when you work on a server without GUI and you want to transfer files over FTP to or from a remote server.
Before You Begin
To be able to transfer files, you must have at least read permissions on the source file and write permission on the target system.
The directory from where you run the
ftp command is the local working directory.
Establishing an FTP Connection
To open an ftp connection to a remote system, invoke the
ftpcommand followed by the remote server IP address or domain name. For example, to connect to an FTP server at “192.168.42.77” you would type:
If the connection is established, a confirmation message will be displayed, and you will be prompted to enter your FTP username, in this example the 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.42.77:localuser): linuxize
You may see a different confirmation message depending on the FTP service running on the remote server.
Once you enter the username you will be prompted to type your password:
If the password is correct, the remote server will display a confirmation message and the
230 OK. Current restricted directory is / Remote system type is UNIX. Using binary mode to transfer files. ftp>
anonymousas username and your email address as a password.
Common FTP Commands
Most of thr FTP commands are similar or identical to the commands you would type in the Linux shell prompt.
Below are some of the most common FTP commands
?- list all available FTP commands.
cd- change directory on the remote machine.
lcd- change directory on the local machine.
ls- list the names of the files and directories in the current remote directory.
mkdir- create a new directory within the current remote directory.
pwd- print the current working directory on the remote machine.
delete- remove a file in the current remote directory.
rmdir- remove a directory in the current remote directory.
get- copy one file from the remote to the local machine.
mget- copy multiple files from the remote to the local machine.
put- copy one file from the local to the remote machine.
mput- copy one file from the local to the remote machine.
Downloading Files with the
Once you are logged in, your current working directory is the remote user home directory.
When downloading files with the
ftp command, the files will be downloaded to the directory from which you typed the
If you want to download the files to another local directory, switch to it by using the
Let’s say we want to download the files to the
To download a single file from the remote server, use the
get command. For example, to download a file named
backup.zip you would use the following command:
The output should look something 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
mget command. You can provide a list of individual file names or use wildcard characters:
mget backup1.zip backup2.zip
When downloading multiple files you will be prompted for confirmation for 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)
Once you are done downloading files from the remote FTP server, close the connection using either the
221-Goodbye. You uploaded 0 and downloaded 6544 kbytes. 221 Logout.
Uploading Files with the FTP Command
To upload a file from a local directory to a remote FTP server, use the
The output should look something 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 upload a file that is not in your current working directory, use the absolute path to the file.
To upload multiple files from a local directory to a remote FTP server, invoke the
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, the command will prompt you to confirm each file you want to upload.
Once you are done uploading files to your remote FTP server close the connection with
In this tutorial, you learned how to use the
ftp command to download and upload files to your remote FTP server.
Feel free to leave a comment if you have any questions.