-->
Previous Table of Contents Next


As you can see, ftp has quite a few commands. However, you really need to look at only the ones that you use most frequently.

Starting an FTP Session

The open command is used to open an FTP session with a remote host. Its syntax is as follows:


open hostname

You usually need this command only if you’re going to connect to more than one site during an FTP session. If you want to connect to only one computer during the session, just specify the remote host name on the command line as an argument to the ftp command.

Ending an FTP Session

The close, disconnect, quit, and bye commands are used to end an FTP session with a remote computer. The identical close and disconnect commands close your connection to the remote computer but leave you in the ftp program on your local computer. The quit, exit, and bye commands close your connection to the remote computer if one is active; then they exit the ftp program on your computer.

Changing Directories

The cd [directory] command is used to change directories on the remote computer during your FTP session. The cdup command takes you to the parent directory of the current directory. The lcd command changes your local directory so that you can specify where to find or put local files.

Remote Directory Listing

The ls command lists the contents of a remote directory, just like ls from an interactive shell. The syntax for ls is this:


ls [directory] [local_file]

If a directory is specified as an argument, ls lists the contents of that directory. If a local filename is given, the directory listing is put into the file you specified on your local computer.

The dir and ls commands provide a long listing, giving protections, size, owner, and date. The syntax of the dir command is as follows:


dir [directory] [local_file]

The following is an example of a dir directory listing:


-rw-r--r--    1 root  archive   2928   May     17     1993     README

-rw-r--r--    1 root  archive   1723   Jun     29     1993     README.NFS

dr-xr-xr-x    2 root  wheel     8192   Jun      6     12:16    bind

-rwxr-xr-x    5 root  wheel     8192   Aug      2     06:11    decus

drwxr-xr-x   19 root  archive   8192   Feb      7     1994     doc

drwxr-xr-x    6 root  wheel     8192   Jun     15     15:45    edu

dr-xr-xr-x    7 root  wheel     8192   Sep     28     09:33    etc


See “Managing File Systems” p. 265 for an explanation of the above result

Getting Files from a Remote System

The get and mget commands are used to retrieve files from a remote computer. The get command retrieves the file that you specify as an argument (filename). The following is the get command’s syntax:


get filename [remote_filename]

You can also give a local filename, which is the name of the file when it’s created on your local computer. If you don’t give a local filename, remote_filename is used.

The mget command retrieves multiple files at once. mget ’s syntax is as follows:


mget filename_list

You specify these files by giving a list of filenames separated by spaces or by using a wildcard pattern to mget. You’re prompted for each file. To turn prompting off, use the prompt command before using mget. In both cases, the files are transferred as ASCII files, unless you’ve set the transfer mode to something else.

Sending Files to a Remote System

The put and mput commands are used to send files to a remote computer. The put command sends the local file that you specify as an argument. The syntax is this:


put filename

The mput command sends a series of local files. The syntax for mput is shown here:


mput filename_list

You specify these files by giving a list of filenames separated by spaces or by using a wildcard pattern to mput. When using mput, you’re prompted for each file. To turn prompting off, use the prompt command. In both cases, the files are transferred as ASCII files, unless you’ve set the transfer mode to something else.

Changing the File Transfer Mode

ftp transfers files as ASCII files unless you specify something else. This is fine for plain text but renders any binary data useless. The ascii and binary commands set the transfer mode so that you can prevent damage to your binary files.


NOTE:  Many files that you’ll want to transfer are in binary format. Files ending with .tar are archives created with the tar command. Files ending in .Z and .gz are compressed with either the compress command or the GNU gzip command, respectively. Files ending in .zip are compressed archives created with PKZIP. When in doubt, use binary transfer mode. Using ASCII mode corrupts binary data files.

Checking Transfer Status

When transferring a large file, you may find it useful to have ftp give you feedback on how far along the transfer is. The hash command causes ftp to print a # character on-screen each time the transmission of a data buffer has been completed. This command works for sending and receiving files.


Previous Table of Contents Next