How to use the Linux ftp command to up- and download files on the shell

In this tutorial, I will explain how to use the Linux ftp command on the shell. I will show you how to connect to an FTP server, up- and download files and create directories. While there are many nice desktops FTP clients available, the FTP command is still useful when you work remotely on a server over an SSH session and e.g. want to fetch a backup file from your FTP storage.

Step 1: Establishing an FTP connection

To connect to the FTP server, we have to type in the terminal window 'ftp' and then the domain name '' or IP address of the FTP server.




ftp [email protected]

Note: for this example we used an anonymous server.

Replace the IP and domain in the above examples with the IP address or domain of your FTP server.

The FTP login.

Step 2: Login with User and Password

Most FTP servers logins are password protected, so the server will ask us for a 'username' and a 'password'.

If you connect to a so-called anonymous FTP server, then try to use "anonymous" as user name and a nempty password:

Name: anonymous


The terminal will return a message like this:

230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

When you are logged in successfully. 

Successful FTP login.

Step 3: Working with Directories

The commands to list, move and create folders on an FTP server are almost the same as we would use locally on our computer, ls for list, cd to change directories, mkdir to create directories...

Listing directories with security settings:

ftp> ls

The server will return:

200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
directory list
226 Directory send OK.

List directories

Changing Directories:

To change the directory we can type:

ftp> cd directory

The server will return:

250 Directory succesfully changed.

Change a directory in FTP.

Step 4: Downloading files with FTP

Before downloading a file, we should set the local ftp file download directory by using 'lcd' command:

lcd /home/user/yourdirectoryname

If you dont specify the download directory, the file will be downloaded to the current directory where you were at the time you started the FTP session.

Now, we can use the command 'get' command to download a file, the usage is:

get file

The file will be downloaded to the directory previously set with the 'lcd' command.

The server will return the next message:

local: file remote: file
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for file (xxx bytes).
226 File send OK.
XXX bytes received in x.xx secs ( MB/s).

Download a file with FTP.

To download several files we can use wildcards. In this example I will download all files with the .xls file extension.

mget *.xls

Step 5: Uploading Files with FTP

We can upload files that are in the local directory where we made the FTP connection.

To upload a file, we can use 'put' command.

put file

When the file that you want to upload is not in the local directory, you can use the absolute path starting with "/" as well:

put /path/file

To upload several files we can use the mput command similar to the mget example from above:

mput *.xls

Step 6: Closing the FTP connection

Once we have done the FTP work, we should close the connection for security reasons. There are three commands that we can use to close the connection:




 Any of them will disconnect our PC from the FTP server and will return:

221 Goodbye

If you need some additional help, once you are connected to the FTP server, type 'help' and this will show you all the available FTP commands.

Share this page:

8 Comment(s)

Add comment


From: dgrb at: 2015-12-01 22:54:02

FTP is not secure, as it transmits usernames and passwords in plaint text. Anyone using a network sniffer can discover them.

No sensible site even enables FTP anymore.

Use SFTP or scp, but plesase DON'T use FTP...

From: till at: 2015-12-02 07:21:49

Seems as if you haven't heard of FTPS yet. FTPS is FTP over SSL/TLS and all current FTP servers support FTPS, so FTP is a secure protocol when your server supports TLS and nobody can sniff any passwords as the connection is fully encrypted. just start the ftp connection with ftps://yourserver.tld instead of ftp://yourserver.tld and you are safe from password sniffing.

From: Sado at: 2015-12-02 14:37:27

You might want to cover the ftp-ssl command as well, it's great for connecting to FTPS sites.


ftp-ssl -pivz secure "$FTP_HOST" 990

From: tina at: 2015-12-08 10:16:38

#you can automate this in a script too , just an example below, ofc one need to parameterize HOST USER FILE, to #be functional in a script eg with getopts or something 

read -s -p "password:" passwd

function getfiles {




ftp -p -v -n $HOST <<END_SCRIPT

quote USER $USER

quote PASS $passwd

type binary

cd /go/to/some/dir

get $FILE



#exit 0



From: jshock at: 2016-02-12 19:13:38

How do you login if your usrname is an email address? For example "ftp [email protected]" won't work. Once ftp sees the @ it assumes the rest is the server address. Quotes, escape character \ and unicode @ don't work either.

From: Younis Raza at: 2016-04-08 17:32:22

Thank you for the FTP tutorial and I could easily follow it. Now would you be kind to let me know how to download sub directories like images, css, includes and so on...?

From: shey samson at: 2016-05-05 05:02:26

It was great to stumble upon this post.

From: ano at: 2016-10-15 20:49:29

Thank's ! <3