Linux ftp command tutorial

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Linux ftp command tutorial

Today I will go through a series of FTP commands from a linux command line, I will show you really simple how to use this without using a 3rd party software like FileZilla for instance. Don’t get me wrong, I recommend Filezilla at any time, but for those who want to use the built-in FTP client from Ubuntu or any other linux operating system, this tutorial could come in handy.

Heads up! You should keep in mind, FTP is an insecure protocol, do not pass sensitive information to a FTP account. It is recommended at this time to use SFTP, it is a much more secured version of FTP.

Connect to FTP server

Using the below commands you can connect to any FTP server.

The end result will be similar to:

You will have to enter a username there and a password and you will be logged in. Once you are logged in, you will see the ftp> prompter there waiting for new commands.

Listing files and folders on FTP

You need to use the ls command to list the content from your location, a sample result is below:

Change directory on FTP

To change the directory you are in, you only need to use the command cd and the name of the folder you want to enter. See below example:

Upload content to FTP

To upload content to your FTP account, one at a time from the local systems to the remote ftp server, enter the command put with the local file name:

Upload Multiple Files to FTP

To upload multiple files from the local system to the remote ftp server use the command mput below:

Keep in mind that you will be prompted to confirm you want to upload the files.

Download / Copy files from FTP

To download one file at a time from the remote ftp server to our local system we would use the get command:

An output similar to below you should be able to see:

Change Local Directory and print remote directory on FTP

You would need to change the local path for you to be able to copy your files or upload your files to your desired location, you can do this using the lcd command:

A similar output you would see if say you want to print the remote directory of your current path, using the command pwd:

The pwd command prints the current path directory of your remote location, on your FTP account. 

Download Multiple Files on FTP

Similar to uploading, you need to use the mget command as follows to copy content from your remote ftp server to the local system. You may be prompted for a yes/no (Y/N) answer before transferring each file (you can disable prompt by passing the -i option to ftp client when connecting). To download all files, enter:

To download all php files (ending with .php extension), enter:

Disable prompting from FTP client

The ftp command prompt sets interactive prompting,

  • on which enables prompting so that you can check download
  • off allows the commands to act without the need of interaction.

This is valid for uploading and downloading from your FTP server.

Delete file from FTP

To delete a file from your current remote directory use the delete command:

Create a new folder on your FTP account:

To create a new folder or directory on your FTP account, you need to use the bellow command mkdir:

Delete a Directory

To remove or delete a directory is a bit different, but using the command rmdir you can do this also:

Change the transfer mode

To set the transfer mode to ASCII, enter:

ascii is the default transfer mode and good this is very good for text files. To set the mode of file transfer to binary, enter:

The binary mode is recommended for almost all sort of files including images, archive files and much more. The binary mode provides less chance of a transmission error.

That’s about it with this tutorial, got it pretty long it seems. See you again in our next tutorial


Request an article ←