An Introduction to FTP

FTP (File Transfer Protocol) Command Examples

FTP - File Transfer Protocol

FTP (File Transfer Protocol) is a networking protocol that is used to transfer files from one computer to another computer using a TCP/IP network. FTP originated before systems had graphical user interfaces. This means that it can be run directly from a command line or command can be embedded into automated scripts easily. FTP allows users to connect with a simple userid and password or on some systems you can connect anonymously. Many newer systems now use SFTP (Secure File Transfer Protocol) as a secure alternative to FTP. FTP generally controls its transfer of data via two connections (ports 20 and 21). One port is for data and the other is for control. The two most popular forms of data transmission by ftp are Ascii which is generally used for text documents and scripts and Binary which is used for image files or compiled binary code.

Basic FTP Commands

In the examples that follow, we are going to concentrate on using ftp from the command line. To see an example of available commands from your terminal session, simply type ftp followed by pressing the "enter" key. Your command prompt should now indicate "ftp>".

Now type a question mark ? followed by "enter". You should now see a list of supported commands:

linux ftp

Whilst at the ftp command prompt, you can then type help followed by the command you are interested in. You will then be given a very simple description of the command. For example: help ascii would return a description of "set ascii transfer type", help lcd would return a description of "change local working directory". help ls return the description of "list contents of remote directory". This "help" function is very useful as a reminder of what some of the commands can do. In the examples that follow later, I will show some of the most frequently used common commands. If this command line interface looks a little daunting, don't panic as there are some excellent GUI (Graphical User Interface) that you can use as an alternative. It is useful though to have an understanding of the basic commands as many Linux servers operate at a runlevel of "3" without a graphical desktop!

Description of FTP commands

FTP Command Description of Command FTP Command Description of Command
! Escape to the Shell $ Execute macro
account Send account command to remote server append Append to a file
ascii set ascii transfer type beep beep when command completed
binary Set Binary transfer type bye Terminate ftp session and exit
case toggle mget upper/lower case id mapping cd Change remote working directory
cdup change remote working directory to parent directory chmod Change file permissions of remote file
close Terminate FTP session cr toggle carriage return stripping on ascii gets
delete delete remote file debug toggle/set debugging mode
dir list contents of remote directory disconnect terminate ftp session
exit terminate ftp sessions and exit form set file transfer format
get receive file glob toggle meta character expansion of local file names
hash toggle printing `#' for each buffer transferred help display local help information
idle get (set) idle timer on remote side image set binary transfer type
ipany allow use of any address family ipv4 restrict address usage to ipv4
ipv6 restrict address usage to ipv6 lcd Change local working directory
ls list contents of remote directory macdef define a macro
mdelete delete multiple files mdir list contents of multiple remote directories
mget get multiple files mkdir make directory on remote machine
mls list contents of multiple remote directories mode set file transfer mode
modtime show last modification time of remote file mput send multiple files
newer get file if remote file is newer than local file nmap set templates for default file name mapping
nlist nlist contents of remote directory ntrans set translation table for default file name mapping
open connect to remote ftp prompt force interactive prompting on multiple commands
passive enter passive transfer mode proxy issue command on an alternate connection
qc print ? in place of control characters on stdout sendport toggle use of PORT cmd for each data connection
put send one file pwd print working directory on remote machine
quit terminate ftp session and exit quote send arbitrary ftp command
recv receive file reget get file restarting at end of local file
rstatus show status of remote machine rhelp get help from remote server
rename rename file reset clear queued command replies
restart restart file transfer at bytecount rmdir remove directory on remote machine
runique toggle store unique for local files send send one file
site send site specific command to remote server size show size of remote file
status show current status struct set file transfer structure
system show remote system type sunique toggle store unique on remote machine
tenex set tenex file transfer type tick toggle printing byte counter during transfers
trace toggle packet tracing type set file transfer type
user send new user information umask get (set) umask on remote site
verbose toggle verbose mode ? print local help information

Basic Syntax for initiating a ftp remote session

Open Connection to a remote host
From the command line enter one of the command options below. You can either supply a fully qualified domain or an IP address:

$ ftp open IP/hostname


$ ftp
ftp> open IP/hostname

After entering the details above, you will be prompted for your ftp account details (userid and password). Some download sites allow anonymous ftp sessions to take place. If this is the case, you may be asked for your email address. (You can type any email address here).

One you have successfully logged in, you may wish to identify which directory you are in. To check this, you can enter the "pwd" command. (Print Working Directory).

ftp> pwd
257 "/" is your current location

List files/directories on remote server

To list files during an active ftp session, we can use the "ls" command. The syntax is very similar to the standard Linux "ls" command, however, it doesn't support all the various parameters that can be passed.

ftp> ls
200 PORT command successful
150 Connecting to port 43532
drwxr-sr-x    4 xxxxxxxx   xxxxxxxx         4096 Jan  6  2010 .
drwxr-sr-x    4 xxxxxxxx   xxxxxxxx         4096 Jan  6  2010 ..
drwxr-s---    4 xxxxxxxx   xxxxxxxx         4096 Jan  9 23:15 html
drwxr-x---    3 xxxxxxxx   xxxxxxxx         4096 Nov 25  2011 mysql

cd - change directory on remote server - lcd - change local directory

From the above listing we can see that there are two directories we can navigate to. The command to accomplish this is the "cd" command (change directory on remote server)

ftp> cd html
250 OK. Current directory is /html
ftp> lcd
Local directory now /home/john

By issuing the "lcd" command, we can workout what our local directory is. This is the local directory on the machine that is initiating the ftp session. If we wanted to change our local directory, we could issue" lcd followed by the new location.

Download (get) a file

ftp> get FileName

The above command will retrieve a file called "FileName" from the directory "html". The file will be placed in the local directory "/home/john". Remember many servers are Unix or Linux based and are case sensitive. In other words, a file called "FileName" can not be retrieved unless you match the name exactly.

Upload (put) a file

ftp> put FileName2

The syntax for sending a file is almost the same as receiving a file. Here we are sending a file called "FileName2" to our remote server. As we are in the remote directory "html", our file will be sent to that location.

Changing a files name on a transfer

When we use the command "put FileName" or "get FileName", we are either sending or receiving a file called "FileName". By specifying an alternative name we can retrieve or send the file with a different name:

ftp> put FileName NewFile1
ftp get FileName NewFile2

In the above example we are sending (put) a file called "FileName" from our local directory "/home/john", however, we have instructed that the file be called "NewFile1" at the remote server. Next we are retrieving a file called FileName and changing its name when arrives in our local directory to "NewFile2".

Sending and Retrieving Multiple files

One of the great features of FTP is its ability to send and receive multiple files that match a pattern:

ftp> ascii
ftp> mget *.txt
ftp> binary
ftp> mget *.jpg

The above example sets the transfer type to that of "ascii". This is the preferred transfer method for text files. Then we issue the command "mget *.txt". This will then retrieve any files that end with the extension of ".txt". Next we change the transfer type to "binary". Binary is used as we are transferring image files. Any files that end in the extension ".jpg" will be transferred to our local directory. To view the files that are to be downloaded, we can issue the "mls *.txt -" command for the text files and "mls *.jpg -" for the image files. You have to specify the "-" after the file pattern. This indicates that we are going to display these names on our screen (stdout).

The sending of multiple files uses the same syntax as the above example, however, we use "mput" :

ftp> mput *.ods

Closing - Terminating a FTP session

To terminate or end a FTP session, we simply send the "quit" command:

ftp> quit
221 Logout. 

Common Error/Message Codes - From FTP servers

Sometimes, when using ftp you will come across various numeric message codes. Some of these numbers indicate that an Acton has successfully completed, whilst others indicate their were issues. The table below lists some of these common codes;

Numeric Code Description
100 Codes The current action is still being processed
110 Restart marker replay
120 Service ready in nnn minutes
125 Data Connection open, transfer starting
150 File status OK. About to open data connection.
200 Codes Action completed successfully
202 Command not implemented
211 System Status
212 Directory Status
213 File Status
214 Help Message
220 Service ready for new user
221 Service Closing Control Connection
225 Data Connection Open.
226 Closing Data Connection, requested action successful
230 User logged in.
231 User logged out, terminated service
232 Logout command noted
250 Requested file action completed OK
300 Codes Command accepted, action on hold waiting further information
331 Username OK, Password needed
332 Account needed for login
350 Requested file action pending further information
400 Codes Command not accepted, Error condition is temporary
421 Service not available
425 Can not open data connection
426 Connection closed, transfer aborted
430 Invalid username or password
434 Host not available
450 Requested file action not taken
451 Requested action aborted
452 Insufficient storage space, file busy, not available
500 Codes Syntax error, command not recognised
501 Syntax error in command or parameter
502 Command not implemented
503 Bad sequence of commands
530 Not logged in
532 Account needed for storing files
550 Action not taken, file not found, no access
551 Page type unknown
552 Exceeded file storage allocation
553 File name not allowed

FTP GUI (Graphical Front Ends for FTP)

Filezilla is one of the most popular GUI interfaces to ftp. Filezilla displays a simple graphical interface with local files left to the left and remote server files on the right.


Filezilla supports FTP over SSL, FTPS and SFTP. Resume functionality exists for large file transfers. Files can be queued for transfer in a queue. You can search remote files, synchronise folders, edit remote files. Files can be moved with simple "drag and drop". Directories can be compared. Filezilla also allows multiple connections to servers via its tabbed interface.

Filezilla should be in most distributions repositories. If you can't find it, then head over to the official site for links to download.
Filezilla Link

Another popular FTP GUI is bareFTP. bareFTP is a simple client for the Gnome desktop. It supports FTP, FTPS and SFTP protocols. Features include resume, append, drag and drop, book marks and active and passive mode selection.

bareftp can be download form the following link bareFTP if you can't find it in your standard repositories.