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 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.
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.
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 index.html changes the permission settings of the index.html 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 file junk.tar.gz from the remote system and saves it as the file junk.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 ftp.netscape.com connects to the FTP server on the host ftp.netscape.com. |
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 index.html sends the index.html 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 old.html new.html renames the file old.html to new.html 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. |
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.
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. |
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, ftp.beta.redhat.com). The pathname is the full directory path and filename of the file you want to download. The username:password is the username and password required to log in to the FTP server. You can leave them out if you want to log in as anonymous user.
Caution |
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:
ftp://localhost
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 ftp://localhost URL, you won't get a response from your system if you are not running an FTP server or if you have set up your firewall such that no FTP connections are allowed.
The same approach of accessing anonymous FTP sites would work if you were to type the hostname of some other anonymous FTP server. For example, try typing the following URL:
ftp://ftp.netscape.com
You should get the directory of the ftp.netscape.com server.