Tutorial For Working With The FTP Command Line

To upload files via the FTP command line, use the 'put' command followed by the file name. For downloads, employ the 'get' command with the file name you wish to retrieve. These essential FTP commands facilitate direct file transfers from your command line, streamlining file management across different operating systems, including Windows.
  1. Blog

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 FTP 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 command line, Solaris, OS X, UNIX, or any other operating system that supports FTP.

FTP Connection And Logging Into The Server

To start using FTP on the command prompt, 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]



ftp connection

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

ftp open name

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

If you're interested in a more secure method of authentication without using passwords, consider exploring SFTP Public Key Authentication.

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

ftp with ip address

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

ftp help

Let's try some of those commands on that list (mkdir, delete, rename, rmdir, glob, verbose, etc).

Listing The Contents Of The Remote Directory

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



Listing The Contents Of The Local Directory

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

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


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, displaying the current local directory (not its contents) is possible without escaping to the shell. You can enter the lcd command like this:

ftp local directory

Changing Your Local Working Directory

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


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

ftp local path

Changing Your Remote Working Directory

The command for changing your remote directory is 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 realize that remotedir1 is actually a subdirectory of that current working directory. Thus, we entered cd remotedir1 instead of typing in the complete path.

We ran the dir command 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 upload the file into the current remote working directory. The succeeding section discusses how to upload a file to a different directory.

ftp 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, 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. You should use this if the files you want to upload have nothing in common, like the filename extension of the first three characters or the last two characters, etc.

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

ftp uploading multiple files

Uploading Multiple Files Using Wildcards

In cases where the files you want to upload have something in common, you can shorten the command by using wildcard characters. 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.

ftp downloading a file

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 must 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.

downloading using wildcards

Several commands exist, but this should be enough to get you started.
Now that you've mastered the fundamentals of using FTP through the command line take your file transfer capabilities to the next level with JSCAPE MFT Server. Experience a secure, managed file transfer solution that supports a wide range of protocols beyond FTP, ensuring compliance and data security. Schedule your free demo today to see how JSCAPE can enhance your file transfer workflows.

Get Your Free Trial

Would you like to try this yourself? JSCAPE MFT Server is platform-agnostic and can be installed on Microsoft Windows, Linux, Mac OS X, and Solaris. It can handle any file transfer protocol and multiple protocols from a single server. Additionally, JSCAPE enables you to handle any file type, including batch files and XML. Download your free 7-day trial of JSCAPE MFT Server now.

Download JSCAPE MFT Server Trial

Related Content

How To Auto Upload Files To A Server From A Local Directory

How To Protect FTP Passwords From Brute Force Attacks

Understanding Key Differences Between FTP, FTPS And SFTP

FTP Binary And ASCII Transfer Types And The Case Of Corrupt Files