Typical FTP Session Using the ftp Command

Connecting to a remote FTP server can require a username and password, but many servers also provide anonymous access. A properly configured remote FTP server responds quickly to FTP

requests, and will display shared directories and files. This section shows a sample FTP session with a typical server found at many Internet sites (in this case, running the wu-ftpd server).

You connect to a remote FTP server by using the ftp command along with either the IP address or hostname of the remote computer, like so:

$ ftp pheniox

Connected to pheniox.

220 pheniox FTP server (Version wu-2.6.1-18) ready. Name (pheniox:tdc): anonymous

331 Guest login ok, send your complete e-mail address as password. Password:

230 Guest login ok, access restrictions apply. Remote system type is UNIX. Using binary mode to transfer files. ftp>

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.

ftp> hash

Hash mark printing on (1024 bytes/hash mark). ftp> prompt Interactive mode off. ftp> bin

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.

ftp> ls

200 PORT command successfui.

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

d—x—x—x 2 root root 4096 Aug 31 07:15 bin d—x—x—x 2 root root 4096 Aug 31 07:15 etc d—x—x—x 2 root root 4096 Aug 31 04:44 iib d—x-x---x 2 root 50 4096 sep 3 07:34 pub

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:

ftp> cd pub

250-Piease read the fiie README

250- it was iast modified on sun sep 2 19:25:47 2001 - 1 day ago 250 cWD command successfui. ftp> ls

200 PORT command successfui.

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

-rw-r—r— 1 root 50 15798 Sep 3 10:29 tftp-0.17-14.i38 6.rpm

server-0.17-14.i386.rpm

2.6.1-22.i386.rpm22 6 Transfer complete.

To transfer all the RPM files to your local machine, issue the mget *.rpm command: ftp> mget *.rpm local: tftp-0.17-14.i386.rpm remote: tftp-0.17-14.i386.rpm 200 PORT command successful.

150 Opening BINARY mode data connection for tftp-0.17-14.i38 6.rpm (15798 bytes).############### 226 Transfer complete.

15798 bytes received in 0.974 secs (16 Kbytes/sec)

local: tftp-server-0.17-14.i386.rpm remote: tftp-server-0.17-

200 PORT command successful.

150 Opening BINARY mode data connection for tftp-server-0.17-

14.i386.rpm (26011 bytes). #########################

226 Transfer complete.

26011 bytes received in 2.5 secs (10 Kbytes/sec) local: wu-ftpd-2.6.1-22.i38 6.rpm remote: wu-ftpd-2.6.1-22.i3 8 6.rpm

200 PORT command successful.

150 Opening BINARY mode data connection for wu-ftpd-2.6.1-

22.i386.rpm (219332 bytes). #################################################################

################################################################# ################################################################# ###################

226 Transfer complete.

219332 bytes received in 50.3 secs (4.3 Kbytes/sec)

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.

0 0

Post a comment