Getting Wired Into the Internet: A Crash Course on FTP, Gopher, Web and More page 3

FTP

The file transfer protocol (ftp) is the most widely used TCP/IP application protocol in terms of traffic. This protocol can copy files from one machine to another. This is not the same as being able to remotely access a file, which is provided by another application layer service. The ftp protocol is analogous to an application like Kermit or XModem, though it also includes some navigational functions. Nearly every commercial TCP/IP offering includes some form of ftp support.

Figure 6 Sample ftp Session
FTP> open nis.nsf.net
Connected to nis.nsf.net.
220 nic.merit.edu FTP server (Version 4.76 Tue Apr 26 02:23:40 EDT 1994) ready.
Name (nis.nsf.net:stevesi): anonymous
331 Guest login ok, send your email address as password.
Password: *********************
230- Guest login ok, access restrictions apply.
230- Local time is: Sun May 1 23:15:31 1994
230
Remote system type is UNIX.
Using binary mode to transfer files.
FTP> help
Commands may be abbreviated. Commands are:
!       debug      mget     pwd     status
$       dir        mkdir    quit    struct
account disconnect mls      quote   system
append  form       mode     recv    sunique
ascii   get        modtime  reget   tenex
bell    glob       mput     rstatus trace
binary  hash       newer    rhelp   type
bye     help       nmap     rename  user
case    idle       nlist    reset   umask
cd      image      ntrans   restart verbose
cdup    lcd        open     rmdir   ?
chmod   ls         prompt   runique
close   macdef     proxy    send
cr      mdelete    sendport site
delete  mdir       put      size
FTP> ascii
200 Type set to A.
FTP> cd documents
250 CWD command successful.
FTP> ls
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 61
-rw-r--r-- 1 nic merit 2300 Jul 31 1992 INDEX.documents
drwxr-sr-x 2 nic merit 512 Mar 19 19:04 fyi
drwxr-sr-x 3 iesg ietf 2048 May 1 07:12 iesg
drwxr-sr-x 154 iesg ietf 3584 May 1 07:13 ietf
drwxr-sr-x 2 iesg ietf 28160 May 1 07:13 internet-drafts
drwxr-sr-x 2 nic merit 20480 Mar 25 22:27 rfc
drwxr-sr-x 2 nic merit 1536 Mar 14 15:17 std
226 Transfer complete.
FTP> cd rfc
250 CWD command successful.
FTP> get rfc0959.txt
local: rfc0959.txt remote: rfc0959.txt
200 PORT command successful.
150 Opening ASCII mode data connection for rfc0959.txt (148550 bytes).
226 Transfer complete.
152483 bytes received in 5.6 seconds (26 Kbytes/s)
FTP> bye
221 Goodbye.

The definitive reference for the ftp protocol is RFC 959, which we show you how to obtain in Figure 6.(ftp://nis.nsf.net/) This example uses the FTP.EXE that comes with Windows NT TM, which is also available with the Microsoft® TCP/IP-32 for WindowsTM for Workgroups product, currently in beta (ftp to ftp.microsoft.com/peropsys/wfw/tcpip/vxdbeta/).

In Figure 6, we are using a command-line interface to ftp, which like all such interfaces provides full power on one hand and plenty of room for mistakes on the other. Fortunately, there are several menu-driven GUI interfaces to ftp available (see Figure 7). We used the command-line interface because it's more common. In Figure 6 the characters entered by the authors are in italic.

Figure 7 Windows Sockets ftp (63.2kb jpeg)

To transfer files with ftp you need several things: a client machine running TCP/IP, a client ftp application, a server running the ftp server process that you can connect to, and some idea of where the file you want is located. In this example, we are connecting to a server that we happen to know contains interesting documents for the Internet, perhaps through a URL that was passed in e-mail or in an MSJ article.

To connect to a server, use the open command, giving a complete host address as the argument. The host address can be either a string name if you have a domain name server, or you can use the dotted-decimal address. As a courtesy, common ftp sites often give both their address and string name. In Figure 6 we are connecting to a server at the NSFNet administrative center. The server is called nis at the nsf second-level domain, in the net top-level domain.

Once we are connected to the server, the server responds asking for a login identifier. You can practically always use the login identifier

anonymous

if you just wish to download software. As a courtesy, you are asked to enter your fully qualified Internet mail address as your password. Although this used to be a convention, some (obnoxious) servers are now enforcing this by parsing your domain name from your e-mail address (all the elements to the left of and including the @) and then attempting to resolve your domain name to the address you're connecting from. This “feature” can be problematic if your e-mail address is on a different system or network from the one you're connecting from, or if you're fortunate enough to have “firewalled” access to the Internet at your organization. If the name cannot be resolved, the server will not allow you to logon; you should ask your local administrator what the appropriate domain name to use is.

Servers use this information merely to maintain a log. According to Internet use policies, administrators are not supposed to use this information for any purpose other than maintaining the security of their servers. You don't need to worry about receiving junk mail or people keeping track of your downloads for competitive reasons. The use of the anonymous login identifier is referred to as anonymous ftp.

Once you are connected to the server, you'll find you've entered a fairly archaic world where your only guidance are conventions that have been established over time. There are three key areas to understand: the standard ftp commands, the organization of files and directories, and the common file formats.

If you are using a GUI front-end you'll have easy access to menu commands to guide you along. If you're not, you'll need a few basic commands for keyboard interaction. In general, ftp commands resemble a subset of the traditional UNIX shell commands (see Figure 8). The first command we entered was help, which, unlike most command shells, actually gets us some assistance. We received a list of all possible commands available on the server.

Figure 8 Common ftp Commands
Command         Description
help                   Print a list of available commands. Sometimes you can get further help on a command by trying the help command (this depends on your client).

open server         Initiate a connection with a system named server.

ascii                  Sets the current transfer mode to ASCII characters, which includes CR/LF translation.

binary                 Sets the current transfer mode to binary, which will transfer a byte image of the file.

cd                      Change directory on the server. You can use ".." to go up a directory.

lcd                      Change the local directory. This allows you to change the current directory, which is usually where downloaded files are stored.

close                   End the current connection and remain in ftp.

bye                     End the current connection and exit ftp.

ls                        filename List a directory, or the attributes of filename.

get sfile dfile       Download a file named sfile. If you do not specify a file, you will generally be prompted for one. It is sometimes desirable to rename a file during transfer by specifying dfile as well.

mget list             Download a group of files in list, which may include server-specific wildcard matching.

put file                Upload a file. If you do not specify a file, you will be prompted for both a remote name and a local name. Note that with anonymous ftp, you will often have limited or no write permissions.

mput list             Upload a group of files in list, which may include client-specific wildcard matching.

We entered the ASCII command, explained further below. Then we used the cd command to change directories and put us into a new directory on the host without affecting the local directory. The get command copies a file from the host to the local machine. In the command-line ftp client the file is copied to the current directory. You can use the lcd command to change the local directory prior to downloading a file if you prefer. The get command usually provides some feedback on how large the file is and some approximation of the time of download. In GUI front-ends you might see a more elaborate progress indicator.

Two important items to note include the ASCII/binary commands and the need to map filenames between different operating systems. The ftp protocol includes a facility to translate text files between different operating systems; for example, systems that require both a CR and LF character to terminate a line. This translation is handled by the client-server interaction, since a standard on-the-wire representation for ASCII was incorporated with the ftp specification. Unfortunately if you download a compressed file in ASCII mode, you will not be able to decompress it since the file will likely have been corrupted. As per the specification, ASCII mode should be the default mode of the server, so be careful to switch to binary. Some of the more clever GUI front-ends to ftp automatically attempt to switch modes based on the file extension, which is a great help.

You might have noticed the feedback from the server in the example that indicated both the remote and local names. In this case they were the same. However, many public ftp sites are UNIX hosts that use long filenames. These filenames must be translated to 8.3 names on a FAT file system; sometimes the client software will do this for you automatically. As you might suspect, a corollary to this rule is that filenames are usually case sensitive on the server, so be careful.

Files are maintained on public ftp sites in a number of standard formats. The most common is the PKZIP format. Files compressed with PKZIP will have a ZIP extension and can be decompressed with PKUNZIP.EXE. Sometimes the files are self-extracting PKZIP archives; these are EXE files that you download and run to decompress. Some other formats include ARC files, which require use of ARC.EXE. These utilities can usually be found in the bin directory of any ftp host.

Normally there is a full index or directory listing for each subdirectory. For example, the host mentioned in Figure 6 has the file INDEX.documents, which is a complete description of the contents of the documents subdirectory. If you need descriptions or if the directory listing is very long, you might download that file, open it in a text editor, and then decide which files to download rather than wasting time and bandwidth by randomly downloading files with awkward names.

You might have noticed that in the sample ftp exchange, I just happened to know what server to connect to and where to go to find a file. You'll often see a reference made to a particular file in a message or an article you've read, and then pull the file down using ftp. Relying on word-of-mouth can be frustrating, though.

An attempt has been made to catalog files on a number of anonymous ftp sites using a TCP/IP application called Archie. Archie provides a simple mechanism for locating files across more than 1,000 public hosts. But this application provides only limited help: the indexes Archie relies on are built from filenames rather than content, so you need to know at least part of the filename that you're interested in locating. Figure 9 shows an example of WinSock Archie being used to locate the PKZIP utility that we talked about earlier. Even though I neglected to provide a URL reference, Archie was able to find the file. Now we can go to ftp.demon.co.uk to get a copy.

Figure 9 WinSock Archie (74.9kb jpeg)

 

For Windows-based developers connected to the Internet, there are a number of anonymous ftp sites to which you might want to connect. These include: ftp.microsoft.com, ftp.cica.indiana.edu, sunsite.unc.edu, and emwac.ed.ac.uk. These hosts maintain large libraries of Microsoft Windows files, bitmaps, applications (freeware and shareware), Windows Sockets utilities, and even sample source code.

Next | Previous | Return to Introduction | Return to Reprints Page