Getting Files from the Internet with ftp


Getting Files from the Internet with ftp

Some of the Internet's great information resources are FTP sites, which contain hundreds of thousands of files from all over the Internet. FTP sites are similar to Web sites, but are directory-oriented and speak a different protocol. They're less fun than the Web usually is but often more practical.

One of the easiest ways to access information on FTP sites is to use anonymous ftp, which lets you access the sites and download files to your computer (Code Listing 12.2, shown on the next page).

Getting a single file through anonymous ftp:

1.

ftp calvin.raycomm.com

At the shell prompt, type ftp followed by the name of the FTP site to which you're connecting. Of course, if the computer has an IP number but no name, type the IP number instead. You'll be prompted to log in, as shown in Code Listing 12.2.

2.

anonymous

For the user name, type anonymous. (Type ftp if you get tired of typing anonymous it nearly always works.)

3.

you@wherever.com

Use your email address for the password. It's polite to identify yourself to the people who provide the FTP service. Just you@ is usually sufficient.

4.

cd /pub/files

Use standard Unix cd commands to move through the directory tree to the file you want.



Code Listing 12.2. Use anonymous ftp to get files from archives across the Internet.

[ejr@hobbes ejr]$ ftp calvin.raycomm.com Connected to calvin.raycomm.com. 220 calvin Microsoft FTP Service (Version 2.0). Name (calvin.raycomm.com:ejr): anonymous 331 Anonymous access allowed, send identity (e-mail name) as password. Password: 230 Anonymous user logged in. Remote system type is Windows_NT. ftp> cd /pub/files 250 CWD command successful. ftp> binary 200 Type set to I. ftp> hash Hash mark printing on (1024 bytes/hash mark). ftp> get jokearchive.gz local: jokearchive.gz remote: jokearchive.gz 200 PORT command successful. 150 Opening BINARY mode data connection for jokearchive.gz(1481035 bytes). ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ################################################################################ ###### 226 Transfer complete. 1481035 bytes received in 4.07 secs (3.6e+02 Kbytes/sec) ftp> quit 221 

5.

binary

Specify the file typein this case, binary, because we're downloading a gzipped archive file. Specify ascii for README files, text, and HTML files.

6.

hash

Next, you have the option of typing hash to tell the ftp client to display a hash mark (#) for every 1, 024 bytes transferred. If you're transferring a small file or using a fast connection, this might not be necessary; however, for large files and slow connections, the hash marks will let you know that you're making progress.

If you'll be downloading multiple files, check out the sidebar Getting Multiple Files in this section before proceeding. The instructions for getting single and multiple files differ at this point in the process.

7.

get jokearchive.gz

At the ftp> prompt, type get and the filename to get the file from the remote system and plunk it into your own account.

8.

quit

When it's finished, just type quit.

Tips

  • If the FTP connection seems to get stuck as soon as you log in, try -yourid@ wherever.com as the password. The character disables system announcements and helps keep your ftp client happy.

  • Some firewallsparticularly the ones on home networksdo not deal gracefully with some of the intricacies of the FTP protocol. If you can connect and log in, but not list files or get anything, the firewall might be the problem. As soon as you log in, type pass (for passive) and the problem should go away.

  • Another handy use for - is to view text files onscreen. For example, type get filename - to have the text just scroll by on the screen.

  • Instead of using get, use newer (as in newer goodjokes.gz) to get a more recent file with the same name as one you have.

  • If you start downloading a file and the FTP connection breaks, type reget and the filename to continue the transfer from wherever it left off. (You'll have to reestablish the connection first, of course.)

  • You can tell the ftp client to make sure that all the transferred files have unique names by using runique instead of get. This way, you can ensure that files don't overwrite existing files on your local system.

  • Use regular Unix commands like ls, pwd, and cd to move around in the remote system, and preface them with an ! to apply to your system. For example, cd .. would change to the next higher directory on the remote system, and !cd .. (from within the ftp client) would change to the next higher directory on the local system. The current local directory is where your files will be saved.


Getting Multiple Files

If you'll be getting multiple files with ftp, follow steps 1 through 6 in this section, then

  • prompt

    Optionally, type prompt to tell the ftp client not to prompt you for each individual file that you want to get. You'll be informed that prompt is set to no. If you want to turn it back on, issue prompt again.

  • mget start*

    At the ftp> prompt, type mget (for "multiple get") followed by the string or filenames to match. In this example, we use start* to get all files with names that begin with "start." You could also use mget *.gz, for example, to get files with the .gz file extension. See Chapter 1 for more about using wildcards.

  • quit

    When you're finished getting files, just type quit.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net