FTP
By -=CrAsH DuMmY=-

Introduction

Everyone have heard of it and all of us frequently use it. But does someone really know how it started and how it really
works. It all started way back in 1971 when the guys at MIT proposed the first transfer mechanisims that were
devloped for implementation on hosts. At this time, the ideas behind FTP were the same as they are today: promote
sharing of files, encourage use of remote computers and transfer data reliably and efficiently. FTP then followed a
slow and constant evolution until 1985, date of the last modifications made to the protocol.

FTP model

Now let's take a look at the FTP model. I is composed of a user-FTP part and a remote sever-FTP part. When a user
wants to establish a FTP data transfer with a server he first send a command from its interface to the user protocol
interpreter. Then, the user-PI sends the FTP command to the server-PI which sends back a FTP reply interpreted by
the user-PI and send to the user interface over the same TCP connexion. After, the server-PI tells the server data
transfer process to set up the data connexion and transfer the data to the passive user-DTP. The user-DTP then
sends one reply to the server-DTP and one other to the user-PI. That's it for the theorical part of FTP transfer and let's
now take a look at the practical part, the commands.

Useful commands

The commands begin with a command code followed by an argument field. The command codes are four or fewer
alphabetic characters. Upper and lower case alphabetic characters are to be treated identically.

The USER ( use: USER [username] ) command is normally the first command transmitted by the user when the set up
for the control connexion is done. It is a Telnet string identifying the user which allows the server to set the access
control level relative to this particular user. Access control define a user's access privileges to the use and access of
a system, and to the files in that system. Access control is necessary to prevent unauthorized or accidental use of
files. Also, the USER command can be used at any time in a FTP session to change the user's privileges.

The PASS ( PASSword ) ( use: PASS [password] ) command is the second command send by the user to
completes the user's identification for access control.

The ACCT ( ACCounT ) ( use: ACCT [account] ) command is an optional command related to the USER login
sequence. Some server may require and account for login. One way to know if the ACCT command needs to be
entered on a given connexion is to look at the reply from the server-PI to the PASS FTP command. Usually, when you
enter the PASS command, the reply to a successful login will be 230. However, if an account is required for login, the
answer will be 332.

The CWD ( Change Working Directory ) ( use: CWD [pathname] ) command allows user user to work with a different
directory without altering his login or accounting information.

The CDUP ( Change to parent Directory ) ( use : CDUP ) command is only a special case of the CWD command to
simplify the process

The REIN ( REINitialize ) ( use: REIN ) command flushes all inputs or outputs and close all connexions excepts the
default control connexion and it allows any transfer in progress to be completed. Usually a USER command is
expected after a REIN.

The QUIT ( logout ) ( use: QUIT ) command terminates a USER command and the server close the control connexion
if there's no active transfer. Else the server will wait for a result on the transfer before closing the connexion.

The following transfer parameter commands must ben implemented before the FTP service request is made.

The PORT ( data PORT ) ( use: PORT [IP,IP,IP,IP,port1,port2] i.e: PORT 226,142,169,67,21,1068 ) command is
used to change the data transfer ports the user and server side. There are defaults values for this command so it is
normally not needed to use it.

The PASV ( PASsiVe ) ( use: PASV [IP,IP,IP,IP,port1] ) command sends a request to the server-DTP to listen for an
upcomming connexion on a specified data port different from the defauld port. So the server-DTP is waiting instead
of initiating a connexion.

The FTP service commands define the file transfer or the file system function requested by the user. The argument of
an FTP service command will normally be a pathname.

The RETR ( RETRieve ) ( use: RETR [pathname] ) command ask the server-DTP to transfer a copy of the requested
file to the user-DTP at the end of the data connexion.

The STOR ( STORe ) ( use: STOR [pathname] ) command cause the server DTP to accept an incomming file from
the data connexion and store it in the server site. If the file already exist, it is automatically replaced by the incomming
file.

The STOU ( STOre Unique ) ( use: STOU [pathname] ) command behaves like the STOR command, except that the
file on the server will have a name unique to this dirrectory. The "250 Transfer Started" response will include the name
generated.

The APPE ( APPEnd ) ( use: APPE [pathname] ) command is used like the STOR command but if the file exist on
the server site, the incomming file is appended to the existing file.

The ALLO ( ALLOcate ) ( use: ALLO [number of bytes] ) command is used to reserve suffisant storage on the
designed server site to accomodate an incomming file. This command is usually followed by a STOP or APPE
command.

The REST ( RESTart ) ( use: REST [pathname] ) command is used to resume an unfinished data transfer. It does not
induce any transfer itself and should be followed by a RETR command.

The RNFR ( RaName FRom ) ( use: RNFR [oldpathname] ) and RNTO ( ReName TO ) ( use: RNTO [newpathname] )
commands are used to rename a file.

The ABOR ( ABORt ) ( use: ABOR ) command tells the server to abort the previous FTP service command and
associated transfer. This command will do nothing if the previous service command is completed. This command
only close the data connexion and will leave the control connexion open.

The DELE ( DELEte ) ( use: DELE [pathname] ) command delete a file.

The RMD ( ReMove Directory ) ( use: RDM [pathname] command remove an existing directory.

The MKD ( MaKe Directory ) ( use: MKD [pathname] command make a directory.

The PWD ( Print Working Directory ) ( use: PWD ) command print the pathname of the working directory.

The LIST ( LIST ) ( use: LIST [pathname] ) command return to the pasive user-DTP a list of all the files in a given
directory or the information about a given file.

The SYST ( SYSTem ) ( use: SYST ) command is used to find out the type of operating system of a server.

The STAT ( STATus ) ( use : STAT ) command cause the server to return current values of all transfer parameters and
the status of connections.

The HELP ( use : HELP [command] ) command is the only command allowed before the USER command and sends
helpful information about the implementation of the control connexion. If used with a command it return information
about that specific command.

FTP replies

The replies to FTP commands ensure that thee user always know the state of the server and if a command have
been successful or not. A FTP reply consists of a three digit number (transmitted as three alphanumeric characters)
followed by some text but on some servers the text is simply not there because the 3 digits contain enough
information for the user-PI and the text is only there for human comprehension. The three digits of the reply each have
a special significance. This is intended to allow a range of very simple to very sophisticated responses by the
user-process.

The first digit denotes whether the response is good, bad or incomplete. There are 5 possiblility for the first digit: 1 (
The requested action is being initiated; expect another reply before proceeding with a new command. ), 2 ( The
requested action has been successfully completed. A new request may be initiated. ), 3 ( The command has been
accepted, but the requested action is being held. The user should send another command specifying this
information.), 4 ( The command was not accepted and the requested action did not take place, but the error condition
is temporary and the action may be requested again. ), 5 ( The command was not accepted and the requested action
did not and will never take place. ).

The second digit refer to the type of error, there are 6 possibilities : 0 ( These replies refer to syntax errors. ), 1 (
These are replies to requests for information, such as status or help. ), 2 ( Replies referring to the control and data
connections. ), 3 ( Replies for the login process and accounting procedures. ), 4 ( Unspecified as yet. ), 5 ( These
replies indicate the status of the server file system vis-a-vis the requested transfer or other file system action. ).

Here's a list of all possible reply codes

110 Restart marker reply.
120 Service ready in nnn minutes.
125 Data connection already open; transfer starting.
150 File status okay; about to open data connection.
200 Command okay.
202 Command not implemented, superfluous at this site.
211 System status, or system help reply.
212 Directory status.
213 File status.
214 Help message.
On how to use the server or the meaning of a particular
non-standard command. This reply is useful only to the
human user.
215 NAME system type.
Where NAME is an official system name from the list in the
Assigned Numbers document.
220 Service ready for new user.
221 Service closing control connection.
Logged out if appropriate.
225 Data connection open; no transfer in progress.
226 Closing data connection.
Requested file action successful (for example, file
transfer or file abort).
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
230 User logged in, proceed.
250 Requested file action okay, completed.
257 "PATHNAME" created.
331 User name okay, need password.
332 Need account for login.
350 Requested file action pending further information.
421 Service not available, closing control connection.
This may be a reply to any command if the service knows it
must shut down.
425 Can't open data connection.
426 Connection closed; transfer aborted.
450 Requested file action not taken.
File unavailable (e.g., file busy).
451 Requested action aborted: local error in processing.
452 Requested action not taken.
Insufficient storage space in system.
500 Syntax error, command unrecognized.
This may include errors such as command line too long.
501 Syntax error in parameters or arguments.
502 Command not implemented.
503 Bad sequence of commands.
504 Command not implemented for that parameter.
530 Not logged in.
532 Need account for storing files.
550 Requested action not taken.
File unavailable (e.g., file not found, no access).
551 Requested action aborted: page type unknown.
552 Requested file action aborted.
Exceeded storage allocation (for current directory or
dataset).
553 Requested action not taken.
File name not allowed.

And now a list of all possible reply codes for each command:

Connection Establishment
120
220
220
421
Login
USER
230
530
500, 501, 421
331, 332
PASS
230
202
530
500, 501, 503, 421
332
ACCT
230
202
530
500, 501, 503, 421
CWD
250
500, 501, 502, 421, 530, 550
CDUP
200
500, 501, 502, 421, 530, 550
Logout
REIN
120
220
220
421
500, 502
QUIT
221
500
Transfer parameters
PORT
200
500, 501, 421, 530
PASV
227
500, 501, 502, 421, 530
File action commands
ALLO
200
202
500, 501, 504, 421, 530
REST
500, 501, 502, 421, 530
350
STOR
125, 150
110
226, 250
425, 426, 451, 551, 552
532, 450, 452, 553
500, 501, 421, 530
STOU
125, 150
110
226, 250
425, 426, 451, 551, 552
532, 450, 452, 553
500, 501, 421, 530
RETR
125, 150
110
226, 250
425, 426, 451
450, 550
500, 501, 421, 530
Informational commands
SYST
215
500, 501, 502, 421
STAT
211, 212, 213
450
500, 501, 502, 421, 530
HELP
211, 214
500, 501, 502, 421

--
-=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=-
~ = [ Knowledge Keepers for Electronic Liberty ] = ~
-=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=-