FTP Commands
In this tutorial, we are going to see the list of FTP Commands. But before we start, you should see What is the FTP protocol.
All communications over the control channel are based on Telnet protocol recommendations. Thus FTP commands are Telnet strings (in NVT-ASCII code) terminated by the Telnet line termination code (i.e., the sequence <CR>+<LF>, Carriage Return followed by the Line Feed character, noted <CRLF>).
If the FTP command accepts a parameter, it is separated from the command by a space (<SP>).
FTP commands allow you to specify:
- The port used
- The data transfer mode
- The structure of the data
- The nature of the action to be performed (Retrieve, List, Store, …)
There are three types of FTP commands:
- Access control commands
- Transfer parameter commands
- FTP service commands
Access control commands
Command | |
---|---|
USER | A string of characters that identifies the user. The identification of the user is necessary to establish a communication on the data channel |
PASS | String specifying the user’s password. This command must be immediately preceded by the USER command. It is up to the client to hide the display of this command for security reasons |
ACCT | String representing the user’s account. This command is usually not necessary. When replying to the password confirmation, if the answer is 230 this phase is not necessary, if the answer is 332, it is necessary |
CWD | Change Working Directory : this command allows to change the current directory. This command requires the path to the directory to be reached as an argument |
CDUP | Change to Parent Directory : this command allows to go back to the parent directory. It was introduced to solve the problems of naming the parent directory according to the system (usually “..”) |
SMNT | Structure Mount |
REIN | Reinitialize |
QUIT | Command to end the current session. The server waits to finish the current transfer, if any, and then provides a response before closing the connection |
Transfer parameter commands
Command | |
---|---|
PORT | Character string to specify the port number to use |
PASV | Command to tell the DTP server to hold a connection on a specific port chosen randomly among the available ports. The response to this command is the IP address of the machine and the port. |
TYPE | This command allows you to specify the type of format in which the data will be sent |
STRU | Telnet character specifying the file structure (F for File, R for Record, P for Page) |
MODE | Telnet character specifying the data transfer mode (S for Stream, B for Block, C for Compressed) |
FTP service commands
Command | |
---|---|
RETR | This command (RETRIEVE) asks the DTP server for a copy of the file whose path is passed in parameter. |
STOR | This command (store) asks the DTP server to accept the data sent on the data channel and to store it in the file with the name passed in parameter. If the file does not exist, the server creates it, otherwise it overwrites it |
STOU | This command is identical to the previous one, except that it asks the server to create a file with a unique name. The name of the file is returned in the response |
APPE | With this command (append) the sent data are concatenated in the file with the name passed in parameter if it already exists, otherwise it is created |
ALLO | This command (allocate) asks the server to provide enough storage space to hold the file whose name is passed in argument. |
REST | This command (restart) allows to resume a transfer where it was stopped. To do this, this command sends as a parameter the marker representing the position in the file at which the transfer was interrupted. This command must be immediately followed by a transfer command. |
RNFR | This command (rename from) allows to rename a file. It indicates the name of the file to be renamed as a parameter and must be immediately followed by the RNTO command |
RNTO | This command (rename to) allows to rename a file. It indicates in parameter the name of the file to rename and must be immediately preceded by the command RNFR |
ABOR | This command (abort) tells the DTP server to abandon all transfers associated with the previous command. If no data connection is open, the DTP server does nothing, otherwise it closes it. The control channel remains open. |
DELE | This command (delete) allows you to delete the file whose name is passed in parameter. This command is irreversible, only a confirmation at the client level can be done. |
RMD | This command (remove directory) allows to remove a directory. It indicates in parameter the name of the directory to remove |
MKD | This command (make directory) allows you to create a directory. It indicates in parameter the name of the directory to create |
PWD | This command (print working directory) returns the full path of the current directory |
LIST | This command returns the list of files and directories in the current directory. |
NLST | This command (name list) allows to send the list of files and directories in the current directory |
SITE | This command (site parameters) allows the server to offer specific services, not defined in the FTP protocol |
SYST | This command (system) allows to send information about the remote server |
STAT | This command (status) allows you to send the status of the server, for example to know the progress of a transfer in progress. |
HELP | This command allows to know all the commands understood by the server. |
NOOP | This command (no operations) is only used to get an OK command from the server. It can be used only to avoid being disconnected after a too high inactivity time |