-->
Previous Table of Contents Next


FTP Commands

Once you have connected to a remote system, you want to move about the directory structure and transfer files. An FTP user has a number of commands available; the most frequently used commands are summarized in Table 15.1. These commands are usually used only with character-based FTP clients, as the GUI-based clients use menu items for these functions.

Table 15.1. FTP user commands.

FTP Command Description

ascii Switch to ASCII transfer mode
binary Switch to binary transfer mode
cd Change directory on the server
close Terminate the connection
del Delete a file on the server
dir Display the server directory
get Fetch a file from the server
hash Display a pound character for each block transmitted
help Display help
lcd Change directory on the client
mget Fetch several files from the server
mput Send several files to the server
open Connect to a server
put Send a file to the server
pwd Display the current server directory
quote Supply an FTP command directly
quit Terminate the FTP session

The primary file transfer commands are get and put. Remember that all commands are relative to the client (the machine you issue the commands on), so a get command moves a file from the server to the client whereas a put command puts a file from the client to the server.

Character-based FTP clients show how this works quite easily. Consider the following example:


get autoexec.bat

705 bytes received in 0.1 seconds (0.00 kbytes/s)

Here the user has logged in to a remote machine, then issued a get command to transfer the file autoexec.bat from the remote (which is a Windows FTP server) to the local client. As you can see, the FTP client issues a status report showing the size of the file and the amount of time it took to transfer.

The mget and mput commands are similar to get and put, but they transfer more than one file at a time. For example, the command:


mget config.*

will transfer all the files name config.* from the FTP server to the local client’s directory. For each file that matches the pattern, the server prompts to make sure you want to transfer it.

You can move around the remote machine using the cd command to change directories and pwd to print the current directory (these are UNIX commands). Note that if you are on a client UNIX machine, the UNIX/ must be used instead of the DOS \ character to indicate directory changes. Again, you have to know the operating system of the remote machine to prevent problems.

File access rights and permissions are always considered by FTP when files are transferred and you move into other directories. If you do not have the proper permissions as set by the server, you can’t perform the action, and you will see an error message.

File Transfer Modes

FTP was developed in the early days of TCP/IP, when practically all files were ASCII format. When binaries had to be transferred (a binary defined as any file that did not have the regular ASCII characters), the mode of the transfer had to be manually changed from ASCII (often called text) to binary. FTP enables file transfers in several formats, which are usually system-dependent. The majority of systems (including UNIX systems) have only two modes: text and binary. Some mainframe installations add support for EBCDIC, while many sites have a local type that is designed for fast transfers between local network machines. (The local type may use 32- or 64-bit words.)

To change the format of the file transfers to allow you to move any file other than a text file, you must first make sure FTP is in binary mode with this command:


bin

You can return to character mode with the command


ascii

It’s important to be aware of which mode you are in. Linux FTP, by default, usually starts in character (ASCII) mode.

Text transfers use ASCII characters separated by carriage-return and newline characters, whereas binary enables transfer of characters with no conversion or formatting. Binary mode is faster than text and also enables for the transfer of all ASCII values (necessary for non-text files). On most systems FTP starts in text mode, although many system administrators now set FTP to binary mode for their users’ convenience. FTP cannot transfer file permissions, as these are not specified as part of the protocol. Some FTP clients and servers can detect the type of file and adjust themselves accordingly. If in doubt, use binary.

Usually there are no keyboard shortcuts (such as pressing the Tab key to fill in names that match) available with FTP. This means you have to type in the name of files or directories in their entirety (and correctly). If you misspell a file or directory name, you will get error messages and have to try again. Luckily, if you are performing the FTP session through an X Window or Windows environment, you can cut and paste lines from earlier in your session.


Previous Table of Contents Next