File Transfer Protocol (FTP) is one of the oldest applications in use on the Internet. First proposed in April of 1971, it predates TCP/IP, the a pair of protocols FTP needs in order to operate. File Transfer Protocol is designed to do exactly that, transfer files between a server and a client. There are many applications which use FTP to transfer files between computers. To use FTP, you can start up the FTP program on your machine and connect to a server. The FTP application you use to connect to the server is a client, and your client software can connect to an FTP server running on port 21 on a remote machine. FTP is included on most of today's operating systems.
How FTP works:
FTP creates both a control and a data connection in order to transfer files. The control connection is based on telnet and is used to negotiate the parameters for the data transfer. This is called an active FTP connection.
- The client FTP application opens a control connection to the server on destination port 21, and specifies a source port as the source to which the FTP server should respond (using TCP).
- The FTP server responds on port 21.
- The FTP server and client negotiate the data transfer parameters.
- The FTP server opens a second connection for data on port 20 to the original client.
- The client responds on the data port, completing a TCP connection.
- Data transfer begins.
- The server indicates the end of the data transfer
- Client closes the connection once the data is received.
- The data connection is closed.
- The FTP connection is closed.
You can get a list of the commands by typing '?' and presing the enter key. Here is a fairly typical list of commands copied from an FTP session originated on a Windows computer.
ftp> ? ! delete literal prompt send ? debug ls put status append dir mdelete pwd trace ascii disconnect mdir quit type bell get mget quote user binary glob mkdir recv verbose bye hash mls remotehelp cd help mput rename close lcd open rmdir ftp> remotehelp 214- The following commands are recognized (* =>'s unimplemented). USER PORT STOR MSAM* RNTO NLST MKD CDUP PASS PASV APPE MRSQ* ABOR SITE XMKD XCUP ACCT* TYPE MLFL* MRCP* DELE SYST RMD STOU SMNT* STRU MAIL* ALLO CWD STAT XRMD SIZE REIN* MODE MSND* REST XCWD HELP PWD MDTM QUIT RETR MSOM* RNFR LIST NOOP XPWD 214 End of help.
INTIATING FILE TRANSFERS FROM THE COMMAND LINE
- On the command line, enter FTP <server name>.
- Enter your login information if prompted.
- Set your transfer mode to either 'ascii' or 'binary' depending upon the type of file you are transferring.
- You can discover what directory you have connected to by entering the comand 'pwd'.
- To change directories on the remote machine, enter 'cd' and the name of the directory.
- To change directories locally, enter 'lcd' To put a file on the remote machine, enter PUT and the name of the file.
- Once the transfer completes, you cen enter 'close' and then 'quit' ('!' and 'bye' also serve the same function as quit).
The passive mode behavior of an FTP server:
- The client opens a connection to the server on TCP port 21 (command channel)
- The server accepts the connection.
- The server initiates a connection to the client using port 20 as the source port (for the data channel)
- The client accepts the connection and acknowledges all data transfers on port 20.
Changing UNIX File Permissions
UNIX and Linux systems use the chmod command to set file permissions. If you are FTP'ing a file to a server, and that file needs special permissions (such as CGI scripts do) you will need to change the permissions on the file. Here's how you do it from the MS-DOS command line:
quote SITE chmod nnn filename
The quote command is part of the local FTP client. The SITE command is a command executed at the server. The chmod command is what changes the mode of the file and the three n's above represent octal numbers that determine the mode of the file.
For more information about UNIX file modes, check your UNIX tutorial.