Blog

Managed File Transfer and Network Solutions

Getting Started With The FTP Command Line

Posted by John Carl Villanueva on Fri, Sep 25, 2015 @ 08:27 AM

This tutorial is for those who 1) understand the vulnerabilities of FTP but still want to learn how it's used AND 2) prefer doing things on the command line. 


The screenshots you'll be seeing here were taken from a Linux machine. However, the commands are the same whether you use Windows, Solaris, OS X, UNIX, or any other operating system that supports FTP.

Connecting and logging into the FTP server

To start using FTP on the command line, launch a terminal screen and then type ftp. After pressing the Return key, you should see a prompt labeled ftp>. This means the system is ready to accept FTP commands. Enter the following command:

open [the hostname or IP address of your ftp server]

e.g. 

open 192.168.100.101

 

 

After pressing the return key, you should then be asked to enter your username on the FTP server. Type it in and then press the return key.

 

 

Next, you'll be asked to enter that username's corresponding password. Again, enter that and then hit return. If the login was a success, you should get a message saying you're now logged in. 

 

 

Another way to do this would be to type in ftp followed by the FTP server's hostname or IP address, like so: 

 

 

As soon as you're inside the FTP user interface (marked by the "ftp prompt"), you can request for a list of supported commands by entering the question mark symbol ?.

 

 

Let's try some of those commands on that list.

 

Listing the contents of the remote directory

To display the contents of the current remote directory on the FTP server, just enter the command:

dir

 

 

Listing the contents of the local directory

The command for listing the contents of the local directory is a little bit different. For that, you'll need to run a local shell command. But before you can do that, you'll have to escape to the shell. This can be done with the exclamation mark !.

In Linux, the command to list the contents of a directory is ls. So, 

!ls

will list all the contents of the local directory.

Note that !ls won't display the contents in the same format as the dir command shown earlier. To display contents in a format similar to the dir command, use the -l option. So the complete command would be:

!ls -l

 

 

Displaying the current local directory

Interestingly, it's possible to display the current local directory (not its contents) without escaping to the shell. You can simply enter the lcd command like this:

 

 

Changing your local working directory 

To change your working directory in the local machine, just add the directory path to the lcd command likeso:

lcd /home/johnv/Documents

If the directory you want to change into is just a subdirectory of your current working directory, then you can simply enter that directory's name like this:

 

 

Changing your remote working directory

The command for changing your remote directory is quite similar to the previous one. Just remove the l ("l" apparently stands for "local"). The screenshot below shows how we changed into the directory named "remotedir1". 

If you scroll back up to the section "Listing the contents of the remote directory" and view the screenshot, you'll realise that remotedir1 is actually a subdirectory of that current working directory. Thus, we simply entered cd remotedir1 instead of typing in the complete path.

We ran the dir command just to show you the contents of that new working directory.

 

 

Uploading a file

To upload a file using FTP, you use the put command. Here's the put command uploading a file named main.txt. Note that this command will simply upload the file unto the current remote working directory. The succeeding section discusses how to upload a file to a different directory.

 

 

Uploading a file to a different directory

If you're familiar with the directory structure of the account on the remote server and want to upload a file to a directory that's not the working directory, you can specify the directory path in the put command like this:

 

 

Notice that, because our destination directory "remotesubdir1" is just a subdirectory of the current remote working directory, we just prefixed that directory with the dot (.). Dot (.) means "current directory".

Notice also that we renamed the newly uploaded file to mainupload.txt. If you want to retain the same name, just use the same name. 

 

Uploading multiple files

The FTP command for uploading multiple files is mput. You can use mput with several space-separated filenames. This is what you should use if the files you want to upload have nothing in common, like say the filename extension or the first 3 characters or the last 2 characters, etc. 

Notice that, before each file is uploaded, you'll be prompted for a confirmation. Just type in y (for yes) to confirm. 

 

 

Uploading multiple files using wildcards

In cases wherein the files you want to upload do have something in common, you can shorten the command by using wildcards. For example, the mput command below uploads all files with the .txt extension.

Just like in the previous mput command, you'll be asked to confirm before each file is uploaded. 

 

 

Downloading a file

The syntax for downloading a file is similar to the syntax for uploading, except that the command is get instead of put. That should be easy to remember, right? Here's an example showing how that command is executed.

 

 

Downloading a file to a different directory

Here's how you download a file to a directory other than the current directory. You'll need to specify the complete path, including the new filename (if you want to change the filename upon download). 

 

 

Downloading multiple files

This is similar to the syntax for uploading multiple files, except that it uses the mget command instead of mput command. Again, you need to confirm each upload with a y (yes).

 

 

Downloading multiple files using wildcards

Here's an example showing how to download multiple files using a wildcard. 

 

 

There are several commands out there but this should be enought to get you started. 

 

Related articles

You might also want to read the following articles:

Setting up a Linux FTP Server

How to FTP a File

Using SFTP On The Command Line

How To Send Large Files Through Email

 

Get started

Want to try these out yourself? You'll need an FTP server to do that. We recommend JSCAPE MFT Server. It's a secure file transfer server that supports FTP and several other file transfer protocols. Download a free, fully-functional evaluation edition now.

 

Download Now

 

Topics: Tutorials, FTP