Table of Contents
- About the Lead Authors
- About the Contributing Authors
- Tell Us What You Think!
- I. Red Hat Linux Installation and User Services
- Chapter 1. Introduction to Red Hat Linux
- Chapter 2. Installation of Your Red Hat System
- Chapter 3. LILO and Other Boot Managers
- Chapter 4. Configuring the X Window System, Version 11
- Chapter 5. Window Managers
- Chapter 6. Connecting to the Internet
- Chapter 7. IRC, ICQ, and Chat Clients
- Chapter 8. Using Multimedia and Graphics Clients
- II. Configuring Services
- Chapter 9. System Startup and Shutdown
- Chapter 10. SMTP and Protocols
- Chapter 11. FTP
- Chapter 12. Apache Server
- Chapter 13. Internet News
- Chapter 14. Domain Name Service and Dynamic Host Configuration Protocol
- Chapter 15. NIS: Network Information Service
- Chapter 16. NFS: Network Filesystem
- Chapter 17. Samba
- III. System Administration and Management
- Chapter 18. Linux Filesystems, Disks, and Other Devices
- Chapter 19. Printing with Linux
- Chapter 20. TCP/IP Network Management
- Chapter 21. Linux System Administration
- Chapter 22. Backup and Restore
- Chapter 23. System Security
- IV. Red Hat Development and Productivity
- Chapter 24. Linux C/C++ Programming Tools
- Chapter 25. Shell Scripting
- Chapter 26. Automating Tasks
- Chapter 27. Configuring and Building Kernels
- Chapter 28. Emulators, Tools, and Window Clients
- V. Appendixes
- A. The Linux Documentation Project
- B. Top Linux Commands and Utilities
- C. The GNU General Public License
- D. Red Hat Linux RPM Package Listings
Using FTP Clients
This section introduces you to several of the FTP clients included with Red Hat Linux. Although the venerable ftp command has remained the standard network file transfer utility and tool of choice for millions of users worldwide, there's always room for improvement. However, the ftp command has a number of features of which many users might not be aware.
Most new and experienced Red Hat Linux users know how to access remote FTP servers by using ftp on the command line along with the name of a remote computer (as described at the beginning of this chapter). You can also speed up anonymous log-ins by using FTP's -a command-line option. However, later versions of the ftp command will also log in and retrieve files with a single command line. To do this, use FTP's auto-fetch capability. Specify an FTP address on the command line with your login, password, name of the computer, and the complete path to the location of a desired file. (You can also use wildcards to retrieve multiple files at one time.) Construct a command line like this:
# ftp ftp://bball:firstname.lastname@example.org/home/bball/happy2.jpg Connected to aptiva.home.org. 220 aptiva.home.org FTP server (Version wu-2.4.2-academ[BETA-18](1) Mon Aug 3 19:17:20 EDT 1998) ready. Remote system type is UNIX. Using binary mode to transfer files. 331 Password required for bball. 230 User bball logged in. 200 Type set to I. 250 CWD command successful. 250 CWD command successful. Retrieving home/bball/happy2.jpg local: happy2.jpg remote: happy2.jpg 227 Entering Passive Mode (192,168,2,36,4,226) 150 Opening BINARY mode data connection for happy2.jpg (34636 bytes). 100% |*******************************************| 34636 00:00 ETA 226 Transfer complete. 34636 bytes received in 0.02 seconds (1.76 MB/s) 221 Goodbye.
As you can see, ftp logged into the remote computer with a name and password, retrieved the file happy2.jpg, and then disconnected. Another ftp command feature is the .netrc, and you can use it to accomplish the same task as the preceding command-line example. First, use your favorite text editor to create the file .netrc in your home directory. Then enter a series of auto-login lines like this:
machine aptiva.home.org login bball password mypassword macdef init get happy2.jpg bye
The first line in the file uses the machine keyword to specify a remote computer. The next two lines specify your remote login and password. The macdef and init keywords specify immediate execution of the init macro. Any FTP commands placed following these keywords and two blank lines will be executed. In this example, the get command is used to retrieve the file happy2.jpg, and the bye command is used to quit the connection.
Save the .netrc file and exit your editor. Next, use the chmod command to give the file read and write permissions of 600, like this:
# chmod 600 .netrc
Finally, to test your .netrc file, use ftp with the hostname of the remote computer on the command line, like this:
# ftp aptiva Connected to aptiva.home.org. 220 aptiva.home.org FTP server (Version wu-2.4.2-academ[BETA-18](1) Mon Aug 3 19:17:20 EDT 1998) ready. 331 Password required for bball. 230 User bball logged in. get happy2.jpg local: happy2.jpg remote: happy2.jpg 227 Entering Passive Mode (192,168,2,36,5,0) 150 Opening ASCII mode data connection for happy2.jpg (34636 bytes). 100% |*******************************************| 34718 00:00 ETA 226 Transfer complete. 34718 bytes received in 0.05 seconds (696.50 KB/s) bye 221 Goodbye.
As you can see, the .netrc file connected, logged in, retrieved the file, and quit the connection. You can use this approach to regularly retrieve files from remote computers (such as weather maps), to regularly upload files to remote sites (such as Web-page directories), or to automate other file transfer tasks (such as regular, remote transfers of system logs through crontab entries).
Getting Files with the wget Command
The wget command, like ftp, may be used to retrieve files quickly and easily with a single command line. However, wget may also be used to retrieve files using Hypertext Transfer Protocol (HTTP) by using a Uniform Resource Locator (URL) like this:
# wget http://www.tux.org/~bball/index.html --13:21:23-- http://www.tux.org:80/%7Ebball/index.html => `index.html' Connecting to www.tux.org:80... connected! HTTP request sent, awaiting response.... 200 OK Length: 6,054 [text/html] OK -> ..... [100%] 13:21:25 (6.54 KB/s) - `index.html'save [6054/6054]
In this example, the file index.html is retrieved via HTTP from a Web site. The wget command may also be used with the ftp:// URL form to retrieve files and can quickly mirror FTP sites. For more details, use the info command to read wget's info file.
The tool-rich Linux environment features many different software tools (such as the expect interpreter) you can use to accomplish difficult tasks. Yet another way to automate file transfers(and other tasks) is with the autoexpect command. The autoexpect command will create an expect script to accomplish tasks performed during an autoexpect session.
To automate an FTP transfer, use the autoexpect command's -f command-line option, followed by the name of the desired command, and an initial command line, like this:
# autoexpect -f eftp ftp aptiva.home.org autoexpect started, file is eftp Connected to aptiva.home.org. 220 aptiva.home.org FTP server (Version wu-2.4.2-academ[BETA-18](1) Mon Aug 3 19:17:20 EDT 1998) ready. Name (aptiva:): bball bball 331 Password required for bball. Password:mypassword 230 User bball logged in. Remote system type is UNIX. Using binary mode to transfer files. ftp> get happy2.jpg get happy2.jpg local: happy2.jpg remote: happy2.jpg 227 Entering Passive Mode (192,168,2,36,5,64) 150 Opening BINARY mode data connection for happy2.jpg (34636 bytes). 100% |**************************************************| 34636 00:00 ETA 226 Transfer complete. 34636 bytes received in 0.03 seconds (1.10 MB/s) ftp> bye bye 221 Goodbye. autoexpect done, file is eftp
This session will create an executable file named eftp, which will connect to the remote computer, log in, retrieve the file happy2.jpg, and then disconnect. To perform the automatic FTP session, type eftp on the command line like this:
The ncftp command is another attempt at improving the ftp command. This program features utilities that help when building shell scripts to automate file retrieval, and offers a pseudo-graphical interface for FTP transfer from the shell command line. According to NcFTP's author, Mike Gleason, this command has a number of unique features:
- Auto-resume downloads
- Background processing
- Cached directory listings
- Command-line editing
- Downloading entire directory trees
- Filename completion
- Host redialing
- Progress meters
- Working with firewalls, proxies, and more
In its simplest form, ncftp may be used just like the ftp command, with the name of a remote computer:
# ncftp aptiva.home.org
For more details about ncftp, see its man page or documentation under the /usr/doc/ncftp directory.
Like ftp and ncftp, John Cristy's xtp command may be used to log in and automatically retrieve one or more files from remote computers. For example, use the xtp command with a complete FTP command-line address like this:
# xtp ftp://bball:email@example.com//home/bball/happy2.jpg
This will log in to the remote FTP server with your username and password, then retrieve the file happy2.jpg and quit the connection. The xtp command has a number of command-line options. For details, use a Web browser such as the text-only lynx browser to read xtp's online documentation, like this:
# lynx /usr/share/Image*/www/xtp.html
Although xtp's online documentation is included with Red Hat Linux, you'll have to go to http://www.wizards.dupont.com/cristy/www/xtp.html for more information or to ftp://ftp.wizards.dupont.com to download a copy.
Brian Masney's gFTP client is an easy-to-use interface to FTP file transfers. You can start this client during your Enlightenment X11 session by clicking the Main Menu button in your GNOME Panel, selecting Internet, and then clicking the gftp menu item. You can also start the gftp command from the command line and specify a remote computer, like this:
# gftp aptiva.home.org
The gFTP client will start as shown in Figure 11.1.
Like other FTP clients, the gftp command supports direct logins. The general syntax for the gftp command line is this:
# gftp [[ftp://][user:pass@]ftp-site[:port][/directory]]
Figure 11.1 The gFTP client supports FTP file transfers with the click of a mouse, and it even supports drag-and-drop file transfers.
This shows that you can use optional keywords, such as ftp://, along with a username, password, particular port number for the remote FTP server, and a destination directory for file transfers. Using this syntax, you can start an FTP session in your directory on a remote computer, like this:
# gftp ftp://bball:firstname.lastname@example.org/home/bball
This will log you in to your remote computer and use a home directory for file transfers.
The gFTP main window (refer to Figure 11.1) features a menu bar with six drop-down menus, two directory windows for the local computer (on the left) and the remote computer (on the right), a progress window (showing the Filename, Progress, and Hostname of the computer), and a scrolling session window showing current activity.
The FTP menu is used to specify the type of file transfers and other options. The Local menu manipulates files and directories, while the Remote menu connects, disconnects, changes servers, and manipulates remote files and directories. The Transfers menu controls the transfer session and uploads (or downloads) files. The Logging menu can be used to keep track of your FTP session. The Tools menu compares the local and remote directories and highlights files that aren't found in both windows. This can make synchronizing file directories between computers a snap!
After you connect, files are transferred between the local and remote computers by clicking a file, and then clicking the appropriate direction arrow in the gFTP dialog box. This sends (or receives) files between computers. Another feature of gFTP, when used during GNOME-enabled X11 sessions, is drag and drop. This means that you can transfer files to a remote computer by clicking and dragging a file from the desktop of the GNU Midnight Commander, and then releasing the file onto the remote computer's file listing window.
Aside from a short man page and README file under the /usr/share/doc/ gftp-2.0-7b directory, you won't find any documentation for the gFTP client on your system. For the latest developments concerning gFTP, go to http://gftp.seul.org.
Using the kfm Command
Built-in network connectivity and utility are some of the newest features brought to the graphical desktop with the advent of today's sophisticated X11 window managers and environments. One of the major benefits of using the K Desktop Environment and GNOME-aware window managers with X11 is that you can combine the drag-and-drop features of a desktop file manager with the FTP and HTTP protocols to quickly and easily download, transfer, and view files.
For example, if you have an active Internet connection and use KDE, you can use the kfm client to perform FTP file transfers using drag and drop. Open a kfm window, such as your home directory, and then type in a remote URL using the FTP form in the Location: field of the client, like this:
After you press Enter, you'll be logged into the site. You can then click to select a file, drag its name to your desktop (or another folder), select Copy from the pop-up menu, and then watch the progress of the download, as shown in Figure 11.2.
Figure 11.2 The kfm client supports FTP file transfers and drag-and-drop objects over an active network!
You can also use multiple selections to download multiple files, or just create symbolic links! If you just create a symbolic link to a file, such as a graphic, when you click on the link on your desktop, and have an active Internet connection, the file will be downloaded and displayed automatically!