How to Use the Linux ftp Command | phoenixNAP KB

Ftp commands


FTP (File Transfer Protocol) is a network protocol used to transfer files from one computer system to another. Although FTP security tends to provoke a lot of discussion, it is still an effective method of transferring files within a secure network.

In this tutorial, we will show you how to use the ftp command to connect to a remote system, transfer files, and manage files and directories.


Access to a

  • local system and a remote FTP server (learn how to install an FTP server on Ubuntu, CentOS 7 or Raspberry Pi).
  • A working Internet connection
  • .

  • Access to the terminal window

. Linux ftp command

syntax The Linux ftp command

uses the

following basic syntax

: ftp [options] [IP] The IP

is the IP address of the system you are connecting to.

The options available for

the ftp command are:


The ftp command connects you to a remote system and starts the FTP interface. The FTP interface uses the following commands to manage and transfer files to the remote system:

Description of the command! $? accountappendasciibellbinarybyecasemgetcdupcdup chmod close crdebugdeletedirdisconnectexitformgetglob hash#helpidle imageipanyipv4 ipv6lcdlsmacdef mdelete mdir mget mkdirmlsmodemodtimemputnewernlist nmap ntransopenpassivepromptproxyputpwdqc? Quit quoterecvreget renameresetrestart rhelprmdirrstatus runiquesendsendportsite sizestruct suniquesystemtenex Check the trace type Detaileduser

How to use

the ftp command on Linux

The ftp command connects a computer system to a remote server using the FTP protocol. Once connected, it also allows users to transfer files between the local machine and the remote system, and manage files and directories on the remote system.


an FTP connection To establish an FTP connection to a remote system, use the ftp command with the IP address of the remote system: ftp [IP] For example, connect to a remote server with IP address

: ftp

log in to

the ftp server Once you initiate a

connection to a remote system by using the

ftp command , the FTP interface requires you to enter a user name and password to log in:

entering the required credentials logs in and starts the FTP interface. In this example, we are logging in as the phoenixnap user

: The FTP interface

is now active and ready to run commands:

Working with directories on a remote system Using FTP, you can perform basic directory management on the remote system,

such as creating directories, moving from one working directory to another, and enumerating the contents of the directory. Directory List The FTP interface allows you to enumerate

the contents of a directory on


remote system

using The ls:ls


Using the command without any options displays the contents of the current working directory of the remote system. In this

example, that’s the home directory: Specifying the path to a directory as an argument to the ls command displays the contents of that directory: ls [path to directory]

For example, enumerate the contents

of the directory Example: ls Example When appending the name of a text file to the end of the

ls command, The contents of a

directory are saved in that file: ls [directory path] [file name] For example: ls



This command syntax requires you to type Y and press Enter to confirm that you save

the text file:

Opening the text file reveals the contents of the directory:

The dir and nlist commands are ls alternatives Order and work in the same way. The FTP interface also allows you to enumerate the contents of various directories using the command mls: mls

[directory 1] [directory 2] .. [directory n] For example, the

following example lists

the contents of Example and Example2: mls Example Example2 –

Like the ls command, the mls command allows users to save the content to a text file. This command treats the last argument as the name of the text file. If you want to enumerate the contents of the directory without saving it to a text file, replace the file name with a hyphen symbol ().

The mdir command

works the same as the mls command but offers a more detailed output: mdir

Example Example2 –

Changing directories

Use the cd

command to change the current working directory on the remote system

: cd [directory path]

For example, move to the directory Example: cd Example

Using the cdup to move to the main working directory of the current one. In this

example, we are moving from the Example directory to the Home directory: cdup

Create directories

Using the mkdir command allows you to create a directory on the remote system: mkdir [directory name]

In the following example, we create a directory named


: mkdir


Download files via FTP

To transfer a file from a remote system to the local machine, Use the get or recv command.

get [remote file name]


recv [remote file name] In the example below,

we transfer example_file.txt to the local machine.

Get example_file.txt To transfer example_file.txt and save it as an example.txt

on your local computer, use

: Get example_file.txt example.txt

Transferring a file from a specific directory requires you to move it to that directory:

cd Get test01 example.txt

The mget command allows you to transfer multiple files at the same time. For example

, transfer test01.txt, test02.txt, and test03.txt from the Example directory: mget test01.txt test02.txt test03.txt

Upload files via FTP

Use the put or send command to transfer a file from the local computer to a remote system. Both commands use the same basic syntax

: put [local file name] send [local file name] To transfer example01.txt to the remote system, use: put example01.txt To upload example01.txt to

the remote system as


, use: put example01.txt sample01


Moving to a specific directory allows you to transfer files from that directory:

cd Directory put example.txt

Use mput to transfer multiple files to the remote system. For example, transfer

test04.txt, test05.txt, and test06.txt with: mput test04.txt test05.txt test06.txt Rename files Use the rename

command to rename files on the remote server. The

rename command uses the following syntax: rename [old file name] [new file name] For example, rename sample01.txt to sample_file01.txt: rename sample01.txt sample_file01.txt

Successful execution of the command produces

the following result:

Use the rename command to also change directory names.

In the following example, the Example3 directory is renamed to Example03: Rename Example3 Example03

Deleting Files

The delete command allows you to delete a file on the remote system. It uses the following syntax

: delete [file name]

For example,

delete sample_file01.txt: delete sample_file01.txt Using the mdelete command

allows you to delete multiple files at the same time by adding the file names after the command: mdelete test04.txt test05.txt test06.txt

Another method is to use the mdelete command with a wildcard character. For example, to delete all .txt files, use:

mdelete *.txt


the FTP connection

Use the bye, exit, or quit command to end the FTP connection and exit the


Using the disconnect command closes the connection without leaving the interface.


After reading this article, you should be able to establish an FTP connection between a local system and a remote server, and use it to transfer files and perform basic file and directory management


If you’re interested in transferring files over the Internet, learn more about SFTP commands, a more secure alternative to FTP.