In this example, ftp is used to connect and then login using anonymous access. This is done by entering the word anonymous at the Name prompt. After pressing Enter, a password prompt is displayed. When using anonymous access, it is considered "good form" to enter your email address as a courtesy. There is no validation of the address entered, but many FTP servers are configured to only accept a valid email address form (that is, [email protected]) if any text is typed at the prompt.

Many FTP servers will accept a simple press of the Enter key at the password prompt if accessed anonymously.

Now that a connection has been established and authenticated to the server, you can then set up your FTP session to work the way you want it to. As mentioned in the previous section, the ftp command has many different built-in commands, which you can view by typing a question mark at the ftp> prompt. These commands can affect the session display, set the type of file transfer, or obtain information about the remote server.

200 Type set to I.

In this example, you have told ftp to print a hash (#) character for every 1024 bytes that are transferred, turn off prompting, and set the transfer type to binary (which should be on by default). The hash character display provides a visual indicator of the progress of your downloads and uploads. Turning off prompting will allow you to send and retrieve multiple files without the need to confirm each transfer. Setting the transfer type to binary will ensure that binary files are transferred in the proper format instead of text, which means that executable files and pictures will transfer correctly.

Next, you ask the server to show a listing of what directories and files are available on the server.

226 Transfer compiete.

If directory permissions in the FTP repository are set correctly, the pub directory should be the only directory that shows any files under it. To verify this, change directories to etc and list the contents.

ftp> cd etc

250 cWD command successfui. ftp> ls

200 PORT command successfui.

150 Opening ascii mode data connection for directory iisting. totai 0

226 Transfer compiete.

By setting the permissions to execute only on the directories bin, iib, and etc, a system administrator can restrict users from seeing any files in that directory. Good security dictates that remote users be denied information about a system, as any information could aid in hacking attempts.

Now that you see the server is relatively secure, change directories to pub and list the contents of that directory:

As described before, the mget command transferred all files with the .rpm extension to our local machine. Furthermore, it did not prompt us to confirm each file because we turned off prompting. The ftp client printed a # for each 1024 bytes transferred to our machine. This is helpful when transferring over a slow connection because you get a visual reminder that your connection is still active.

After every action, the FTP server will return a status code and brief message showing the result of the command you issued. You can find a listing of all status codes and their corresponding messages in Request For Comment 959; you can access a copy of this listing at http://www.ietf.org/rfc/rfc959.txt.

Now you are finished with this session; you can issue the command quit to end the session. Additionally, the FTP server will inform you of how many bytes your session transfers, how many files, and the total transferred data (in bytes) between your local machine and the server.

ftp> quit

221-You have transferred 503818 bytes in 5 files.

221-Total traffic for this session was 506422 bytes in 7 transfers. 221 Thank you for using the FTP service on pheniox.

This is a simple example, but average FTP sessions are similarly trivial. Several other commands are available during an FTP session, but they are rarely used. FTP has the capability to take scripted input and define macros that allow for a much more complicated session.

The FTP info pages are much like the man (manual) pages shipped with almost every command in Linux. More detailed information may be found in the command's source code package.