|
The Internet is full of FTP servers, computers that store large archives of files that are available for download. Most FTP servers allow anyone to download files, using a system called anonymous FTP, which means that you type anonymous as your username when you log in to the FTP server.
To download files from an FTP server (or upload files to an FTP server, if you have permission to do so), you run an FTP program. The UNIX FTP program is called ftp, as you may already have guessed. When downloading files, you've got to connect to the FTP server that stores the file, tell the FTP program which file you want, and indicate whether the file contains text ("ASCII") or something else ("BINARY"). FTP needs to know this because different types of computer systems store text files in different ways; specifically, they use different characters to indicate the end of each line of text. When you transfer a text file, FTP adjusts the line-ending characters for the computer system you are copying the files to. When you transfer any other kind of file, FTP doesn't fool with the contents of the file at all. Remember that if you are calling into a UNIX account by using a terminal program on your PC or Macintosh, it takes two steps to get a file from an FTP server to your own computer. First, you use FTP to copy the files from the FTP server to your Internet provider's computer. Second, you still have to download it to your computer. How hard can it be to copy a file from one place to another?It's relatively simple to copy a file from one place to another (but don't forget -- computers are involved). Here's how it works: Log in to the other computer for FTP and tell it what you want to copy and where you want it copied to. Here's how to use the ftp program to download a file (that is, to copy a file from the FTP server to your computer).Run the ftp program, by typing the name of the FTP server on the command line. To connect to the wuarchive.wustl.edu FTP server, for example, type this line:
You see a bunch of messages, confirming that you are connected and asking for your account name:
Type your username on the FTP server. If you don't have one, type anonymous. If you log in as anonymous, you see a message like this:
Next, the FTP server wants to know your password. If you typed a username, type your password. If you logged in as anonymous, type your e-mail address as your password. You see messages from the FTP server telling you what the rules of the server are, and then you see the ftp> prompt, which means that the FTP server is waiting for your command. Go to the directory on the FTP server that contains the file you want, using the cd command, like this (this command moves to the docfiles directory):
To see the files in the current directory, type dir. You see a directory listing with filenames and sizes, like this:
When you find the file you want, tell the FTP server what kind of file it is. For text files, type ascii. For all other files, type binary or image. Use the get command to copy it to your computer. For example, type:
If you are using a UNIX shell account, the get command copies the file to your provider's computer, not to your own computer. You see messages like this:
When you finish copying files, log off the FTP server, by using the quit command. You see a friendly message:
That's basically how FTP works, but of course you need to know about 400 other odds and ends to use FTP effectively. The first directory you see on the FTP server may contain file with names such as read.me or index.txt. It's a good idea to download and view these files before continuing. The directory thicketYou use the dir command to see what's in a directory. Most FTP servers run an operating system called UNIX. When you use the FTP dir command, you see a standard UNIX directory listing, in which the first letter on the line tells you whether something is a file or a directory. d means that it's a directory -- anything else is a file.If you want to see some but not all of the files in the current directory, you can type a filename after the dir, and you can use * in the filename to match an character or characters. For example, to see a listing of files that begin with z, you type:
If you see any directories in the current directory, the cd command changes directories. It changes the current directory on the FTP server but doesn't affect the current directory on your UNIX system. You can also change the directory on your own computer, using the lcd command. (You might expect cd to change directories correspondingly on both machines, but it doesn't.) To move up to the directory that contains the current directory (the parent directory, as they say), type:
What's in a name?You can change the name of a file when you download it. Because filenames in UNIX can be longer than they can on pre-Windows 95 PCs, you may have to use a different name for the file when you download it. To store the file by using a different name from the one it has on the FTP server, type the name you want to use at the end of the get command, like this:
This command downloads the file named rose-photograph and names it rose2.gif. Grabbing a buncha filesSuppose that you want to get a bunch of the files that begin with ru. In that case, you can use the mget (which stands for multiple GET) command to retrieve them. The names you type after mget can be either plain filenames or wildcard patterns that match a bunch of filenames. For each matching name, FTP asks whether you want to retrieve that file, as in the following:
Note: If you find that mget matches more files than you expected, you can stop it with the usual interrupt character for your system -- typically Ctrl-C or Delete. You can even interrupt in the middle of a transfer if a file takes longer to transfer than you want to wait. This game of 20 Questions is OK for three or four files, but it can get darned tedious if you want to copy a bunch of them. Fortunately, you also can do an express mget, which doesn't ask any questions and enables you to find exactly the files you want. Suppose that you use the dir command to see information about a bunch of files you might want to download:
Now suppose that you want all those 92-1 files and don't feel like hammering on the y key to tell FTP to get all the files. Use the prompt command, which tells FTP not to ask any questions in mget but to just do it:
About face!OK, now you know how to retrieve files from other computers. How about copying the other way? It's just about the same procedure except that you use put rather than get. That is, you log on to the FTP server and use the cd and dir commands to find the directory to which you want to upload the file. Then you use put to copy the file to the FTP server, and quit to log off. Simplicity itself!The following example shows how to copy a local file called rnr to a FTP server and rename the file rnr.new on the server:
(As with get, if you want to use the same name when you make the copy, leave out the second name.) The mput command works just like the mget command does, only in the other direction. If you have a bunch of files whose names begin with uu and you want to copy most of them, issue the mput command, as in the following example:
(As with mget, you can use prompt to tell it to go ahead and not to ask any questions.) Most systems have protections on their files and directories that limit where you can copy files. You generally can use FTP to put a file anywhere that you could create a file if you were logged in directly by using the same login name. If you're using anonymous FTP, you generally cannot put any files at all. Other FTP shenanigansA bunch of other file-manipulation commands are sometimes useful, as in the following example of the delete command:
This command deletes the file on the remote computer, assuming that the file permissions enable you to do so. The mdelete command deletes multiple files and works like mget and mput. The mkdir command makes a new directory on the remote system (again assuming that you have permissions to do so), as in the following example:
After you create a directory, you still have to use cd to change to that directory before you use put or mput to store files in it. If you plan to do much file deleting, directory creating, and the like, it's usually much quicker to log in to the other system by using telnet to do your work and using the usual local commands. | |
![]() |
Return to previous section |
Internet Gurus Home | Search This Site | Our Books |
Internet Gurus Central webmaster@gurus.org |
"...For Dummies" is a registered trademark of Wiley Publishing, Inc.
© Copyright 1998-2011 I.E.C.C. Last update August 5, 2009. |