FTP Commands and Replies

FTP Commands and Replies

PCBWay

We end this section with a  brief discussion of some of the more common FTP commands and replies. The commands, from each client to server, and replies, from server to client, are sent across the control connection in 7-bit ASCII format. Thus, like HTTP commands, FTP commands are readable by people. In order to delineate successive commands, a carriage return and line feed end each command. Each command consists of four uppercase ASCII characters, some with optional arguments. Some of the more common commands are given below:

DRex Electronics
  • USER username: Used to send the user identification to the server.
  • PASS password: Used to send the user password to the server.
  • LIST: Used to ask the server to send back a list of all the files in the current remote directory. The list of files is sent over a (new and non-persistent ) data connection rather than the control TCP connection.
  • RETR filename: Used to retrieve (that is, get) a file from the current directory of the remote host. This command causes the remote host to initiate a data connection and to send the requested file over the data connection.
  • STOR filename: Used to store (that is, put) a file into the current directory of the remote host.

There is typically a one-to-one correspondence between the command that the user issues and the FTP command sent across to the control connection. Each command is followed by a reply, sent from server to client. The replies are three-digit numbers, with an optional message following the number. This is similar in structure to the status code and phrase in the status line of the HTTP response message. Some typical replies, along with their possible messages, are as follows:

  • 331 Username OK, password required
  • 125 Data connection already open; transfer starting
  • 425 Can’t open data connection
  • 452 Error writing line

Readers who are interested in learning about the other FTP commands and replies are encouraged to read RFC 959.