Understanding FTP
As the name implies, the File Transfer Protocol (FTP) enables users to transfer files between systems on the Internet. FTP is client/server software-you can use the FTP client on a system to access files on another Internet host. The FTP server on that host acts on commands you send via the FTP client.
The FTP clients and servers exchange information by using the FTP, described in RFC 959, 'File Transfer Protocol,' by J. Postel and J. K. Reynolds, October 1985. FTP uses two TCP ports-data is transferred on port 20, while control information is exchanged on port 21.With FTP, you can download files from other Internet hosts or from hosts in your local area network. Reciprocally, users on other systems also can download files from your system, typically through a feature known as anonymous FTP. You learn how to set up anonymous FTP service in the section 'Setting up Secure Anonymous FTP.'
Before you can try out the FTP client, log in as root and start the vsftpd server on your system with the following command:
service vsftpd start
In pervious versions of Red Hat Linux, the FTP server was run under xinetd. Starting in Red Hat Linux 9, the FTP server runs as a standalone server, just like Apache httpd and the innd news server. To automatically start vsftpd when you boot the Red Hat Linux system, you must turn it on with the following command:
chkconfig --level 35 vsftpd on
The next few sections introduce you to FTP for transferring files and working with remote directories. In addition to the FTP commands, you also learn about the graphical FTP clients and how to use FTP through your Web browser.
Using the Command-Line FTP Client
After you have started vsftpd, you can see how FTP works by using the command-line FTP client. You can try out the FTP commands from another system on a local area network or on your Red Hat Linux system. For example, the following sample FTP session shows how I use the command-line FTP client to log in using my user name (naba ) and browse the directories on my system (my comments appear in italics):
ftp localhost
Connected to localhost (127.0.0.1).
220 (vsFTPd 1.1.3)
Name (localhost:naba): (I press Enter)
331 Please specify the password.
Password: (I type my password)
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> help
Commands may be abbreviated. Commands are:
! debug mdir sendport site
$ dir mget put size
account disconnect mkdir pwd status
append exit mls quit struct
ascii form mode quote system
bell get modtime recv sunique
binary glob mput reget tenex
bye hash newer rstatus tick
case help nmap rhelp trace
cd idle nlist rename type
cdup image ntrans reset user
chmod lcd open restart umask
close ls prompt rmdir verbose
cr macdef passive runique ?
delete mdelete proxy send
ftp> cd /var/ftp (This changes directory to /var/ftp)
250 Directory successfully changed.
ftp> ls (This command lists the contents of the directory)
227 Entering Passive Mode (127,0,0,1,121,193)
150 Here comes the directory listing.
d--x--x--x 2 0 0 4096 Jan 09 19:31 bin
d--x--x--x 2 0 0 4096 Jan 09 19:31 etc
drwxr-xr-x 2 0 0 4096 Jan 09 19:31 lib
drwxr-sr-x 2 0 50 4096 Dec 13 16:13 pub
226 Directory send OK.
ftp> bye (This command ends the session)
221 Goodbye.
As the listing shows, you can start the command-line FTP client by typing the command ftp hostname , where hostname is the name of the system you want to access. Once the FTP client establishes a connection with the FTP server at the remote system, the FTP server prompts you for a user name and password. After you've supplied the information, the FTP client displays the ftp > prompt, and you can begin typing commands to perform specific tasks. If you can't remember a specific FTP command, type help to view a list of them. You can get additional help for a specific command by typing help command.
Many of the FTP commands are similar to UNIX commands for navigating the file system. For example, cd changes directory, pwd prints the name of the current working directory, and ls lists the contents of the current directory. Two other common commands are get and put -get downloads a file from the remote system to your system, and put uploads (sends) a file from your system to the remote host.You can use the mget command to download multiple files. However, you cannot conveniently download entire directory hierarchies by using the command-line FTP client. Graphical FTP clients are much better at downloading entire directories and subdirectories.
Table 17-1 describes some commonly used FTP commands. Note that you do not have to type the entire FTP command. For a long command, you have to type the first characters only-enough to identify the command uniquely. For example, to delete a file, you can type dele, and to change the file transfer mode to binary, you can type bin.
Command | Description | ||
---|---|---|---|
! | Executes a shell command on the local system. For example, !ls lists the contents of the current directory on the remote system. | ||
? | Displays list of commands (same as help ) | ||
append | Appends a local file to a remote file | ||
ascii | Sets the file transfer type to ASCII (or plaintext). This is the default file transfer type. | ||
binary | Sets the file transfer type to binary | ||
bye | Ends the FTP session with the remote FTP server and quits the FTP client | ||
cd | Changes directory on the remote system. For example, cd /pub/Linux changes the remote directory to /pub/Linux . | ||
chmod | Changes the permission settings of a remote file. For example, chmod 644 indexl changes the permission settings of the indexl file on the remote system. | ||
close | Ends the FTP session with the FTP server and returns to the FTP client's prompt | ||
delete | Deletes a remote file. For example, delete bigimage.jpg deletes that file on the remote system. | ||
dir | Lists the contents of the current directory on the remote system | ||
disconnect | Ends the FTP session and returns to the FTP client's prompt. (This is the same as close.) | ||
get | Downloads a remote file. For example, get junk.tar.gz junk.tgz downloads the filejunk.tar.gz from the remote system and saves it as the filejunk.tgz on the local system. | ||
hash | Turns on or off hash mark (# ) printing showing the progress of file transfer. When turned on, a hash mark is printed for every 1,024 bytes transferred from the remote system. | ||
help | Displays a list of commands | ||
image | Same as binary | ||
lcd | Changes the current directory on the local system. For example, lcd / var/ftp/pub changes the current local directory to /var/ftp/pub . | ||
ls | Lists the contents of the current remote directory | ||
mdelete | Deletes multiple files on a remote system. For example, mdelete *.jpg deletes all remote files with names ending in .jpg in the current directory. | ||
mdir | Lists multiple remote files and saves the listing in a specified local file. For example, mdir /usr/share/doc/w* wlist saves the listing in the local file named wlist . | ||
mget | Downloads multiple files. For example, mget *.jpg downloads all files with names ending in .jpg . If prompt is turned on, the FTP client asks for confirmation before each file is downloaded. | ||
mkdir | Creates a directory on the remote system. mkdir images creates a directory named images in the current directory on the remote system. | ||
mls | Same as mdir | ||
mput | Uploads multiple files. For example, mput *.jpg sends all files with names ending in .jpg to the remote system. If prompt is turned on, the FTP client asks for confirmation before each file is sent. | ||
open | Opens a connection to the FTP server on the specified host. For example, open | prompt | Turns prompt on or off. When prompt is on, the FTP client prompts you for confirmation before downloading or uploading each file during a multifile transfer. |
put | Sends a file to the remote system. For example, put indexl sends the indexl file from the local system to the remote system. | ||
pwd | Displays the full path name of the current directory on the remote system. When you log in as a user, the initial current working directory is your home directory. | ||
quit | Same as bye | ||
recv | Same as get | ||
rename | Renames a file on the remote system. For example, rename oldl newl renames the file oldl to newl on the remote system. | ||
rmdir | Deletes a directory on the remote system. For example, rmdir images deletes the images directory in the current directory of the remote system. | ||
send | Same as put | ||
size | Shows the size of a remote file. For example, size bigfile.tar.gz shows the size of that remote file. | ||
status | Shows the current status of the FTP client | ||
user | Sends new user information to the FTP server. For example, user naba sends the user name naba; the FTP server then prompts for the password for that user name. |
Using a Graphical FTP Client
GNOME comes with gFTP, a graphical FTP client. To start gFTP, select from the GNOME desktop Main Menu>>Internet>>More Internet Applications>gFTP. This starts the gFTP application to run and display its main window.
The gFTP window (Figure 17-1) has a menu bar with menus for performing various tasks. Just below the menu bar is a toolbar with a number of buttons and text fields. Here, you can type the name of the remote host, the user name, and the password needed to log in to the remote host. After you supply the host and user information, click the button with the icon of two computers to the left of the Host field. This causes gFTP to connect to that host and to log in with the user name and password you have provided.Figure 17-1 shows the gFTP window after you have connected to the remote FTP site and moved around the remote directories in prepartion for downloading some files.

Figure 17-1: The gFTP Window after Connecting to a Remote FTP Server.
The middle part of the gFTP window is divided into two parts. The left side shows the contents of the current local directory; after establishing a connection, the right side shows the contents of the remote directory. Once the directories are listed, transferring files is simple. Simply select the desired files in the list, clicking the left arrow button to download or the right arrow button to upload.The best part about using gFTP is that you can download entire directories by simply selecting the directories on the right-hand side window and clicking the left arrow.To disconnect, click the computer button again. You can then quit the gFTP application by selecting FTP>Quit from the menu.
Insider Insight | gFTP is not for FTP transfers alone. It can also transfer files using the HTTP protocol and secure file transfers using the Secure Shell (SSH) protocol. |
Using a Web Browser as an FTP Client
Any Web browser can act as an FTP client, but they are best for anonymous FTP downloads, where the Web browser can log in using the anonymous user name and any password.In Red Hat Linux, you can use the Mozilla Web browser as an FTP client. All you need to do is provide the URL that tells the Web browser to download a file using FTP. The syntax of the FTP URL is
ftp://username:password@hostname/pathname
The first part (ftp:// ) indicates that you want an FTP transfer. The hostname part should be the name of the FTP server (the name often starts with an ftp -for example,
When you provide the username and password in the URL, the password is in plaintext and can be read by anyone who looks at the URL.
If the URL has only the hostname for the FTP server, the Web browser displays the contents of the anonymous FTP directory. If you want to try this on your Red Hat Linux system, start Mozilla (click the Mozilla icon on the GNOME panel), and then type the following line in the location text box:
Then press Enter. Mozilla shows the contents of the anonymous FTP directory on your Red Hat Linux system. You can click on folders to see their contents and download any files.When you use the