Chapter 7 from An Incomplete Guide to the Internet and Other Telecommunications Opportunities Especially for Teachers and Students K-12 Compiled by the NCSA Education Group July, 1993 Chapter 7: Teaching Your Computer How to Fetch or How to FTP FTP: What it is and why. The File Transfer Protocol (FTP) is the Internet standard for moving files from one computer to another. You can use the ftp command to copy computer files containing a variety of kinds of information, such as software, documentation, or maps. FTP is the name not only of the protocol, but also of the program the user invokes to execute it (e.g., by typing ftp host.bbn.com). Anonymous FTP, like Telnet, requires access to the Internet . Unlike Telnet, anonymous FTP is widely available. The term anonymous is used to denote the fact that most individuals logging into the remote machine do not have their own accounts but use the generic user account anonymous. Anyone can become an Internet traveler by using the ftp command. The following short tutorial should be sufficient to introduce the novice to using ftp. It is primarily designed for those users who are not directly connected to the Internet. For those individuals who are already connected, additional software packages, like Fetch for the Macintosh computer, exist. These programs greatly facilitate the process of file transfer. Because FTP is used to transfer files between two computers on a network, this tutorial assumes that you have access to a computer on the Internet and some familiarity with the Unix operating system. The tutorial begins at a point after you have logged into this computer. In this exercise, you'll be transferring a popular mail utility for the Macintosh family of computers. Named Eudora, this email utility is available at many anonymous ftp sites including ftp.cso.uiuc.edu in the directory /mac/eudora. For those owners of IBM computers or compatibles, PC-Eudora will become available, but is still in the testing stage at this time. If you're interested in a similar utility, there is one by the name of NUPop at the anonymous ftp host casbah.acns.nwu.edu in the directory pub/nupop. Simply replace the host and directory information in the tutorial with these. The file that you will want to transfer is nupop103.zip. Before you begin I'll be referring to the computer that is our initial Internet contact as the local computer and the computer that we ftp to as the remote computer. Prompts will be displayed in bold to differentiate them from computer output. Your prompt should look something similar to my Unix prompt - landrew.ncsa.uiuc.edu_51%. The prompt for the ftp program is ftp>. Underlined text indicates a user command and should be entered exactly as they appear. Lines in courier type face are output (what you will see on your computer screen that you didn't put there). Sentences in the standard type face are short descriptions explaining user input and computer output. And so we begin. Note: The program and the operating systems that are on the Internet are case sensitive. A file named 'readme' is different from a file named 'Readme'. Setting up a temporary directory -------------------------------- For this tutorial, we'll be setting up a temporary directory in our Unix account on our local computer. I find that this is a good idea whenever I transfer files. See the Unix section of this manual, if you have additional questions about the commands 'mkdir' and 'cd' landrew.ncsa.uiuc.edu_51% mkdir tempdir This command creates a new directory named 'tempdir'. landrew.ncsa.uiuc.edu_52% cd tempdir By changing our current directory to the one we just created, we ensure that any files that we transfer will be placed into this directory. Opening a session ----------------- landrew.ncsa.uiuc.edu_53% ftp ftp.cso.uiuc.edu With this command, we have told our computer to run the program ftp and to use the address ftp.cso.uiuc.edu. The ftp program will attempt to open a connection to the computer at this address. In the future, you will be knowledgeable enough about the resources on the Internet to want to ftp to a machine of your choosing. This can be done by replacing the address ftp.cso.uiuc.edu with any valid address of a computer on the Internet. If the connection attempt is successful, you will be asked to login. Connected to ftp.cso.uiuc.edu. 220 ux1.cso.uiuc.edu FTP server (Version 6.12 Fri May 15 15:45:18 CDT 1992) Name (ftp.cso.uiuc.edu:jduban): anonymous Since the computer at ftp.cso.uiuc.edu supports anonymous ftp, we'll be using the guest account anonymous. This will be true for virtually every machine to which you will ftp. 331 Guest login ok, send e-mail address as password. Password: -------- At this point, they request that you enter your email address as a password. This is the case for virtually every anonymous ftp site on Internet. Note that your password does not appear on the screen. After your login, a short message similar to the following usually appears. 230- This is an experimental FTP server. If your FTP client crashes or 230- hangs shortly after login please try using a dash (-) as the first 230- character of your password. 230- 230- Please read the file /README 230- it was last modified on Fri Jun 5 11:06:41 1992 - 233 days ago 230- Guest login ok, access restrictions apply. The message contains pertinent information for users. It is in your best interest to read this message and any other files it suggests. These messages frequently let the user know when the site is available and what restrictions apply to anonymous logins. This message suggests that we read the file named 'README'. Generally, the information in any 'README' file is stored as text. The next section shows how to 'get' the 'README' file mentioned above and display it on your screen. Getting and reading a text file ------------------------------- ftp>get README We've just told the computer to get us the file named README from the remote machine. The computer responds with the following. 200 PORT command successful. 150 Opening ASCII mode data connection for README (4248 bytes). 226 Transfer complete. local: README remote: README 4341 bytes received in 0.16 seconds (26 Kbytes/s) ASCII mode - indicates that the computer is transferring a text file Transfer complete - indicates that the transfer of the file was successful With the file on our local computer, we can use the following commands to display the file on the screen. ftp> !more README The ! allows us to give our local computer a command. We have invoked the program 'more' and told it to display the file named 'README'. Your screen will be filled with the contents of the 'README' file. For more information on 'more', refer to the Unix section of this manual. After reading the contents of the file, we're ready to move on. Navigation on the remote computer --------------------------------- Let's see what else is in the current directory. The 'ls' command will help us achieve this goal. If you're interested in learning more about the commands like 'ls', please refer to the Unix section of this manual. For now just enter the following command at the prompt. ftp>ls -l We've requested a long listing (ls -l) of the current directory on the remote computer. Whenever an 'ls -l' is done the computer will respond with something similar to the following. 200 PORT command successful. 150 Opening ASCII mode data connection for /bin/ls. total 258 -rw-r--r-- 1 zinzow ftp 4248 Jun 5 1992 README drwxrwxr-x 11 root amiga 1024 Jan 13 22:56 amiga drwxrwxr-x 15 138 wheel 512 Jan 4 21:02 doc -rw-r--r-- 1 zinzow ftp 145528 Jan 2 1992 ftp.list drwxrwxr-x 8 root mac 512 Jan 21 00:57 mac 226 Transfer complete. 1825 bytes received in 0.32 seconds (5.6 Kbytes/s) To the new user, a long listing may appear to be chaotic and meaningless. But in truth there is a great deal of information to be gleaned from this listing. Of the items that would interest you, are those in the first, fourth, fifth and sixth columns. From the 1st column, you can tell whether the file is a directory (denoted by a 'd' in the left most position) or a file (denoted by a '- '). The 4th column shows the size of each entry in the directory in bytes (characters). The 5th column is the date when the file was last changed. The 6th column contains the names of the files. Individuals using guest access are usually restricted to which directories they can enter and which files that they can transfer. Later, when you explore the world of anonymous ftp on your own, do not be surprised to see a message indicating that you do not have enough privileges to access certain files or directories. Now that we know that there is a directory named mac, let's see what's in it. ftp> cd mac Change the directory from the current one to the sub-directory titled mac. 250 CWD command successful. ftp> ls -l Let's see what's in this directory. Again, we're using the 'ls' command, to list the files in the current directory (/mac). 200 PORT command successful. 150 Opening ASCII mode data connection for /bin/ls. total 50 -rw-rw-r-- 1 dlong 18842 Nov 5 1991 FAQlist.txt lrwxr-xr-x 1 root 22 Dec 10 19:57 MUG... -rw-rw-r-- 1 dlong 13593 Nov 3 1990 SIMTE... drwxr-xr-x 6 116 512 Nov 18 00:05 eudora drwxrwxr-x 2 root 512 Feb 18 1991 exec-pc drwxrw-r-x 2 zinzow 512 Jan 31 1992 local drwxrwxr-x 2 zinzow 512 Oct 29 20:51 sys7 -rw-r--r-- 1 root 9528 Jan 21 01:01 oar.out drwxrwxr-x 2 dlong 512 Sep 17 1991 utils drwxrwxr-x 2 root 1024 Jul 6 1992 virus 226 Transfer complete. remote: -l 584 bytes received in 0.14 seconds (4.1 Kbytes/s) The 5th line of the listing tells us that there is a directory named eudora. The Eudora program should lie within this directory ftp> cd eudora Change the directory from the current one to the sub-directory titled eudora. Note: We could have shortened the process by combining the multiple change directory commands into 1 command - cd /mac/eudora. This command would have brought us to the same directory in fewer steps. 250 CWD command successful. ftp> ls -l Get a listing of the files in the current directory (/mac/eudora). 200 PORT command successful. 150 Opening ASCII mode data connection for /bin/ls. total 3940 -rw-r--r-- 1 root 0 Jul 9 1992 .notar -rw-r--r-- 1 116 9660 Aug 16 1991 1.2Changes -rw-r--r-- 1 116 730150 Nov 2 21:52 1.2man.glue.sit.hqx -rw-r--r-- 1 116 826074 Jul 3 1991 .2man.pm.sit.hqx -rw-r--r-- 1 116 17069 Oct 8 02:04 1.3Changes -rw-r--r-- 1 116 11407 Apr 2 1992 README -rw-r--r-- 1 116 11291 Oct 8 02:04 ReleaseNotes -rw-r--r-- 1 116 5890 Jun 5 1992 Appendix-d drwxr-xr-x 3 116 512 Jan 12 22:59 beta -rw-r--r-- 1 116 838381 Jan 17 1992 comm1.i.sit.hqx -rw-r--r-- 1 116 88352 Nov 26 1990 diskcopy.hqx -rw-r--r-- 1 116 950580 Oct 17 1991 doc.i.sit.hqx -rw-r--r-- 1 116 459636 Oct 18 1991 eudora1.2.2.i.sit.hqx drwxr-xr-x 3 116 512 Nov 17 01:37 intl drwxr-xr-x 2 116 512 Aug 7 22:07 oldbeta -rw-r--r-- 1 116 7589 May 11 1992 srialpop.c drwxr-xr-x 2 116 512 Feb 18 1992 tables 226 Transfer complete. remote: -l 993 bytes received in 0.42 seconds (2.3 Kbytes/s) The file that we want is called 'eudora1.2.2.i.sit.hqx'. Additionally, it is also a good idea to get the 'README' file and one of the eudora manuals. This site has the complete Eudora manual in 2 forms; '1.2man.glue.sit.hqx' contains the manual in glue form and includes a program to read it, the '1.2man.pm.sit.hqx' file contains the manual in a Page Maker 4.0 file. We'll transfer '1.2man.glue.sit.hqx' since not everyone has a copy of Page Maker. For those individuals who don't have DiskCopy for the Macintosh, we'll need to transfer the file 'diskcopy.hqx'. Let's get these files. Transferring files ------------------ Of the three files, the 'README' file is text file. No matter which remote machine that you connected to, the 'README' files will always be text files. The other two files have the suffixes .sit and .hqx. The suffixes indicate that these files are not text files but are actually stored in binary form. As such, we will have to tell ftp to transfer these files in a different manner. Note: See the "Archiving suffixes" section of this manual for more information about suffixes. We'll transfer the 'README' file first. Since it is a text file, we can use the same command that we used earlier. ftp>get README 200 PORT command successful. 150 Opening BINARY mode data connection for README (11407 bytes). 226 Transfer complete. local: README remote: README 11407 bytes received in 1.4 seconds (7.8 Kbytes/s) Usually, it is a good idea to scan the 'README' file for important information before transferring any other files. For the purpose of this tutorial it is not necessary but you can if you wish to do so. Remember the command that we used to display the 'README' file? Its !more README. Note: Since the names of two text files were the same, 'README', the first file has been overwritten and is now gone. This is true for any files that may have duplicate filenames; the older version will be over written. See the 'mv' command in the Unix section of this manual if you want to keep a copy of the older file. Before we transfer the next two files, we need to tell the ftp program that these files are binary and need to be transferred in binary form. This is achieved by the following command. ftp> bin 200 Type set to I. The transfer mode has been changed to binary. ftp> get eudora1.2.2.i.sit.hqx Get the file 'eudora1.2.2.i.sit.hqx'. The computer will tell us if the transfer was successful and how long it took. 200 PORT command successful. 150 Opening BINARY mode data connection for eudora1.2.2.i.sit.hqx (459636 bytes) 226 Transfer complete. local: eudora1.2.2.i.sit.hqx remote: eudora1.2.2.i.sit.hqx 459636 bytes received in 8.7 seconds (51 Kbytes/s) Since the transfer of the first file went smoothly, we can now get the manual that accompanies Eudora. ftp> get 1.2man.glue.sit.hqx 200 PORT command successful. 150 Opening BINARY mode data connection for 1.2man.glue.sit.hqx (730150 bytes). 226 Transfer complete. local: 1.2man.glue.sit.hqx remote: 1.2man.glue.sit.hqx 730150 bytes received in 21 seconds (34 Kbytes/s) We transfer the third file in the same manner. ftp> get diskcopy.hqx 200 PORT command successful. 150 Opening BINARY mode data connection for diskcopy.hqx (88352 bytes). 226 Transfer complete. local: diskcopy.hqx remote: diskcopy.hqx 88352 bytes received in 1.2 seconds (71 Kbytes/s) After transferring the last file we can now exit the ftp program. This is done using the following command. ftp>bye The ftp program responses with: 221 Goodbye. And places you back at your system prompt. Let's see what our local directory looks like. Remember how to do that? landrew.ncsa.uiuc.edu_54%ls The command 'ls' gives us a listing of the current directory but does not include all of the file information that 'ls -l' does. 1.2man.glue.sit.hqx diskcopy.hqx README eudora1.2.2.i.sit.hqx You should see the four files listed above. You now have these files at your local machine. For those individuals using modems, you may want to turn to the section of this manual that will walk you through transfer of the files to your personal computer. For those lucky individuals that have their personal computer directly connected to the network, you may wish to turn to the section on archiving suffixes and decompression. This section will help you extract the files from the archive you have just downloaded. This must be done to put the files into a usable form. Summary of the commands in the ftp tutorial ------------------------------------------- This is designed to be a template for ftping any file from any Internet site. The name of the remote computer ftp.cso.uiuc.edu, the directory /mac/eudora and the files transfered can be easily changed to suit your own purpose. Prompts are displayed in bold to help differentiate them from user input. The prompt for the ftp program is ftp>. Underlined text indicates a user command. landrew.ncsa.uiuc.edu_51%mkdir tempdir Create a temporary directory to transfer files into. landrew.ncsa.uiuc.edu_52%cd tempdir Enter the directory just created. landrew.ncsa.uiuc.edu_53% ftp Start the ftp program & ftp.cso.uiuc.edu ask it to open a connection to a remote computer. In this tutorial we will be logging into the computer - ftp.cso.uiuc.edu. Name (ftp.cso.uiuc.edu:jduban): At the prompt, login as anonymous anonymous. Password: Enter your email address when it prompts you for a password. Ex. jdoe@ncsa.uiuc.edu ftp>get README Get the README in the default directory. It might contain important information. ftp> !more README Check to see what the system administrators have to say. ftp>cd /mac/eudora Change the directory to the one which contains the application. ftp>get README Get the README file in the /mac/eudora directory. It probably contains important information ftp>bin Change the transfer mode to binary. Necessary for all files other than text files. Text files do not have any suffixes like .hqx or .sit. ftp>get eudora1.2.2.i.sit.hqx Transfer the eudora application ftp>get 1.2man.glue.sit.hqx Transfer the Eudora 1.2 manual. ftp>get diskcopy.hqx Transfer DiskCopy. ftp>bye Close the connection and quit the ftp program. This will return you to your system prompt. The following commands are recognized by ftp: append local-file [ remote-file ] Appends a local file to a file on the remote machine. If remote-file is not specified, the local file name is used in naming the remote file. File transfer uses the current settings for type, format, mode, and structure. ascii Sets the file transfer type to network ASCII. This is the default type. bell Arranges for a bell to sound after each file transfer command is completed. binary Sets the file transfer type to support binary image transfer. bye Terminates the FTP session with the remote server and exits ftp. case Toggles the remote computer's file name case mapping during mget commands. When case is on (default is off), the remote computer's file names are written in the local directory with all letters in upper case mapped to lower case. cd remote-directory Changes the working directory on the remote machine to remote-directory. cdup Changes the remote machine working directory to the parent of the current remote machine working directory. close Terminates the FTP session with the remote server and returns to the command interpreter. cr Toggles the carriage return stripping during ascii type file retrieval. Records are denoted by a carriage return/linefeed sequence during ascii type file transfer. When cr is on (the default), carriage returns are stripped from this sequence to conform with the UNIX single linefeed record delimiter. Records on non-UNIX remote systems may contain single linefeeds; when an ascii type transfer is made, these linefeeds may be distinguished from a record delimiter only when cr is off. delete remote-file Deletes the file remote-file on the remote machine. dir [ remote-directory ] [ local-file ] Prints a listing of the directory contents in the directory, remote directory, and, optionally, places the output in local file. If no directory is specified, the current working directory on the remote machine is used. If no local file is specified, output comes to the terminal. disconnect A synonym for close. form format Sets the file transfer form to format. The default format is file. get remote-file [ local-file ] Retrieves the remote-file and stores it on the local machine. If the local filename is not specified, it is given the same name it has on the remote machine. The current settings for type, form, mode, and structure are used while transferring the file. lcd [ directory ] Changes the working directory on the local machine. If no directory is specified, the user's home directory is used. ls [ remote-directory ] [ local-file ] Prints an abbreviated listing of the contents of a directory on the remote machine. If remote-directory is left unspecified, the current working directory is used. If no local file is specified, the output is sent to the terminal. mdir remote-files local-file Obtains a directory listing of multiple files on the remote machine and places the result in local-file. mget remote-files Retrieves the specified files from the remote machine and places them in the current local directory. If globbing is enabled, the specification of remote files will first be expanding using ls. mkdir directory-name Makes a directory on the remote machine. mls remote-files local-file Obtains an abbreviated listing of multiple files on the remote machine and places the result in local-file. mput local-files Transfers multiple local files from the current local directory to the current working directory on the remote machine. open host [ port ] Establishes a connection to the specified host FTP server. If an optional port number is supplied, ftp attempts to contact an FTP server at that port. If the auto-login option is on (default), ftp automatically attempts to log the user in to the FTP server (see below). prompt Toggles interactive prompting. Interactive prompting occurs during multiple file transfers to allow the user to retrieve or store files selectively. If prompting is turned off (default), any mget or mput transfers all files. get and mget transfer files from the host on the primary control connection to the host on the secondary control connection put, mput, and append transfer files from the host on the secondary control connection to the host on the primary control connection. Third party file transfers depend upon support of the ftp protocol PASV command by the server on the secondary control connection. put local-file [ remote-file ] Stores a local file on the remote machine. If remote-file is unspecified, the local file name is used in naming the remote file. File transfer uses the current settings for type, format, mode, and structure. pwd Prints the name of the current working directory on the remote machine. quit A synonym for bye. recv remote-file [ local-file ] A synonym for get. rename [ from ] [ to ] Renames the file from on the remote machine, to the file to. reset Clears the reply queue. This command re-synchronizes command/reply sequencing with the remote ftp server. If the remote server violates the ftp protocol, resynchronization may be necessary. rmdir directory-name Deletes a directory on the remote machine. runique Toggles storing of files on the local system with unique filenames. If a file already exists with a name equal to the target local filename for a get or mget command, a .1 is appended to the name. If the resulting name matches another existing file, a .2 is appended to the original name. If this process continues up to .99, an error message is printed, and the transfer does not take place. The generated unique filename will be reported. Note that runique will not affect local files generated from a shell command (see below). The default value is off. send local-file [ remote-file ] A synonym for put. status Shows the current status of ftp. sunique Toggles storing of files on a remote machine under unique file names. The remote ftp server must support the ftp protocol STOU command for successful completion of this command. The remote server reports the unique name. Default value is off. tenex Sets the file transfer type to that needed to talk to TENEX machines. trace Toggles packet tracing. type [ type-name ] Sets the file transfer type to type name. If no type is specified, the current type is printed. The default type is network ASCII. user user-name [ password ] [ account ] Identifies the user to the remote FTP server. If the password is not specified and the server requires it, ftp disables the local echo and then prompts the user for it. If an account field is not specified, and the FTP server requires it, the user is prompted for it also. Unless ftp is invoked with auto login disabled, this process is done automatically on initial connection to the FTP server. verbose Toggles the verbose mode. In verbose mode, all responses from the FTP server are displayed to the user. In addition, if verbose is on, statistics regarding the efficiency of a file transfer are reported when the transfer is complete. By default, verbose is on. ? [ command ] A synonym for help. Command arguments which have embedded spaces may be quoted with quotation (") marks. Aborting a file transfer To abort a file transfer, use the terminal interrupt key (usually ). Sending transfers are halted immediately. Receiving transfers are halted by sending a ftp protocol ABOR command to the remote server, and discarding any further data received. The speed at which this is accomplished depends upon the remote server's support for ABOR processing. If the remote server does not support the ABOR command, an ftp> prompt appears when the remote server has completed sending the requested file. The terminal interrupt key sequence is ignored when ftp has completed any local processing and is awaiting a reply from the remote server. A long delay in this mode may result from ABOR processing, or from unexpected behavior by the remote server, including violations of the ftp protocol. If the delay results from unexpected remote server behavior, the local ftp program must be killed by hand. File-naming conventions Files specified as arguments to ftp commands are processed according to the following rules: 1) Standard input is used for reading and standard output is used for writing when the file name is specified by an en dash (-). 2) If the first character of the file name is a vertical line (|), the remainder of the argument is interpreted as a shell command. The ftp command then forks a shell, using popen(3) with the argument supplied, and reads (writes) from the stdout (stdin). If the shell command includes spaces, the argument must be quoted, as in ""| ls -lt"". A particularly useful example of this mechanism is: "dir |more". 3) If globbing is enabled, local file names are expanded according to the rules used in the csh(1) (compare to the glob command). If the ftp command expects a single local file, such as put, only the first filename generated by the globbing operation is used. 4) For mget commands and get commands with unspecified local file names, the local filename is the remote filename and can be altered by a case, ntrans, or nmap setting. The resulting filename may then be altered if runique is on. 5) For mput commands and put commands with unspecified remote file names, the remote filename is the local filename and may be altered by a ntrans or nmap setting. The resulting filename can then be altered by the remote server if sunique is on.