The File Transfer Protocol (FTP)


FTP is used to transfer files between computers. It is a complex protocol that enables the exchange of data files using different methods of data representation and file storage. In its simplest form, FTP uses clear-text username and password exchanges and is not considered to be a very secure utility. FTP was originally created when the Internet was still composed mostly of large business, government, and educational institutions, and a breach of security wasn't considered that big of a threat. When used on the Internet, however, most every legacy TCP/IP utility is best used in a secure environment. The commands in this chapter show you how to use FTP. To ensure a secure exchange of information, be sure to read the chapters in Part VIII, "System and Network Security."

The syntax for FTP varies from one vendor's implementation to another. However, the simplest format, used to initiate a connection, is

 ftp  hostname  

in which you simply follow the ftp command with a hostname ”for example, ftp ftp.archive.org . You also can use the dotted -decimal address instead of the DNS name of the system with which you want to establish a connection. Alternatively, you can enter ftp at the command prompt and then, from the ftp> prompt, enter the commands needed to accomplish a particular task.

Tip

The Web site ftp.archive.org is a great place to practice using ftp commands, and is also a great place to obtain a lot of free files if you are interested in historical films . At this site you can set your default directory to pub\movies and will find several thousand "ephemeral" films that have been encoded in several different digital formats (take your pick).

These films include everything from home movies to corporate films, as well as TV commercials and ”for us old folks ”those flicks you used to see in high school way-back-when, telling you how to behave on a date! This site is a treasure trove of files that you should investigate if you have any interest in twentieth-century life.

A lot has changed in the past 20 to 30 years . More secure forms of authentication and data exchange have been added to create more secure forms of FTP. Before we look at a few common FTP clients and their syntaxes, let's look at the basic FTP protocol and get a feel for how it works.

Note

The File Transfer Protocol can be found in a large number of RFC documents that were created over the years. The main RFC that most documents point you to is RFC 959, "File Transfer Protocol (FTP)." RFC 2151, "A Primer on Internet and TCP/IP Tools and Utilities," is also a nice read and covers many of the utilities in this chapter. RFC 2228, "FTP Security Extensions," deals with the inherent security problems found in the FTP protocol. This last RFC discusses extensions that can be used to provide for secure authentication and encryption for the FTP protocol. In addition, there are several proposed RFCs that are on the path toward becoming a standard. RFC 2640, "Internationalization of the File Transfer Protocol," and RFC 2428, "FTP Extensions for IPv6 and NATs," provide insight into the future of FTP.

FTP is based on a client/server architecture. An FTP server (called a daemon on Unix or Linux systems and a service on Windows systems) manages a file system (anything from a single directory to a disk farm). FTP servers authenticate the client user using a username and password, and then work with the client to transfer files between the client and server computers. The basic protocol is a simple exchange of messages . Traditional FTP uses a simple command-line interface. Today, many shareware and commercial GUI versions of FTP are available. For example, if you are already using a favorite FTP site, try using a URL such as ftp://ftp.archive.org to see whether your browser supports a GUI interface for FTP. Either way, command line or GUI, it is an extremely useful utility because it allows the transfer of many types of files between two hosts on the network.

Note

FTP clients come in many forms. As mentioned in the text of this chapter, you can use a command-line interface using a computer running Unix/Linux or any Windows operating system. Most browsers support the prefix "ftp" just as they do the "www" prefix when browsing Internet sites. You can also download GUI FTP applications that operate outside the command line or browser interface. Use a search engine and you will find many of these applications. Most differentiate themselves from others by providing additional features, such as an easy-to-use interface or integration with other applications, such as Windows Explorer.

FTP Ports and Processes

The FTP server daemon listens in the background for FTP requests on TCP port 21. In the literature, the server is composed of two components , though they are often combined into a single program. The first is the Server-PI, which stands for "server protocol interpreter." This is the component that listens to TCP port 21 and interacts with its client counterpart , the User-PI. The user protocol interpreter initiates an FTP session by sending a request to the server. The client's request can include a port that the client wants the server to use when it opens a data channel.

The second component of the server is the Server-DTP, which stands for "server data transfer process." This is the code that interacts with its counterpart, the User-DTP, to perform the actual file data transfers. An overview of this process appears in Figure 26.1. The important thing to notice in this figure is that two channels of communication are used for FTP ”one for commands and one for the actual exchange of data ”and that both of these channels work in both directions.

Figure 26.1. The FTP session consists of both a command and a data channel.

graphics/26fig01.gif

The client's User-PI should be listening on the specified port for incoming data transmissions before it has issued the commands necessary to start a data transfer from a remote server. The actual commands used on the control connection are in the same format used for the telnet utility (NVT-ASCII), which is discussed later in this chapter.

Data Transfers

All FTP data transfers take place using bytes (8 bits), independent of the size of the actual data being transferred. That is, if the local file system uses a different size for storage, such as a word or a floating-point numerical representation, FTP just sends 8 bits at a time. The data is reconstructed on the receiving end into its original format. The client and server applications are responsible for making sure that conversions are done on their end to make data usable on their respective systems.

When you're using an FTP client, it is important that you know what type of file you are sending or receiving. The default for most clients is to send/receive ASCII text files. If you want to send or receive an executable program, most clients use the command "binary" to inform the server you interact with that this is not an ASCII text file.

Additionally, there are three modes that are used for transfers:

  • Stream mode ” This is a simple transmission of a stream of bytes. To represent record and file structures using this mode, End of Record (EOR) and End of File (EOF) control bytes can be used. Control bytes consist of 2 bytes. The first byte is set to all ones (which is the escape character), and the second byte is the control character. A value of 1 for this byte indicates that it is the EOR character. A value of 2 indicates that it is the EOF character. A value of 3 indicates both characters (EOR and EOF). Note that if an actual byte of all ones is in the data stream, it is transmitted as a 2-byte sequence also, with both bytes being set to all ones.

  • Block mode ” This transmission mode sends a series of data blocks, each of which has a header. The header information consists of 3 bytes of information. The 16 lower-order bits indicate the byte count, which is the total length of the block ( expressed in bytes). The remaining high-order byte is used for a descriptor code. A descriptor code value of 128 indicates that the end of a data block is the end of a record (EOR). A value of 64 indicates that the end of a data block is the end of a block of data (EOF). A value of 32 is used to indicate that there is reason to suspect errors in the data stream.

  • Compressed mode ” In this mode, data can be sent using various compression mechanisms.

All transfers are done in 8-bit bytes, regardless of the way the bits are interpreted on the receiving system. The data types that FTP allows are very basic. The ASCII type consists of standard 8-bit NVT-ASCII characters. In this format, the carriage -return and line-feed characters are used to indicate the end of a line. Some systems, such as many Unix systems, do not use this combination of characters, and the receiving side converts the received stream of bytes to its own format.

The EBCDIC type (Extended Binary-Coded Decimal Interchange Code) is a method of character representation used mainly on IBM mainframe computers, which were quite popular back when development on FTP (and its predecessors) first started. The EBCDIC and ASCII transfers are sent as 8-bit characters and are similar, with just the character representations of the numerical values differing.

The IMAGE mode of transfer sends data as a simple stream of bits, which are stored in the usual 8-bit transfer byte used by FTP. At the receiving end, the bits are stored in a contiguous manner, with padding added to the end of a file or record as necessary. The method used must ensure that the process of this padding can be reversed if the file is transferred to another system that does not use that method.

The LOCAL type allows the user to set a logical size for the bytes to be sent. All data is still sent as a byte, but on the receiving end this command allows the receiver to know how to reassemble the bits into the correctly sized bytes for that operating system.

FTP Protocol Commands

This section looks at some of the more useful commands that the protocol uses to control an FTP session. This is not an exhaustive discussion of all possible protocol commands, however. The next section looks at examples of the syntax for FTP for several implementations so that you can see how various FTP applications work, and how their command structure matches up user commands to the commands actually used by the FTP protocol processes.

Note that these "protocol commands" are the commands exchanged by client and server applications on the network. Commands entered by an end user are a different matter altogether. Many end-user commands involve a sequence of protocol commands to accomplish the desired function. Here we examine the commands exchanged between the server and client applications, not the command entered by a user.

FTP protocol commands start with the command code itself and are usually followed by one or more arguments. All FTP protocol commands are four characters or fewer and can be grouped into a few categories:

  • Access Control Commands (ACT) ” These are used to authenticate the user, change directories, and so on.

  • Transfer Parameter Commands (TPC) ” These commands control the actual data transfer process, such as the port used and the file structure.

  • FTP Service Commands (FSC) ” These commands indicate the function the user wants to perform, such as sending or receiving a file, or perhaps renaming or deleting a file.

Table 26.1 is a list of commonly used commands along with a description of their use.

Table 26.1. FTP Protocol Commands

Command

Type

Description

USER

ACT

This command is followed by a username valid on the remote system.

PASS

ACT

This command is followed by the password associated with the remote user account.

ACCT

ACT

Some implementations require a text string identifying a user account, which is sent with this command.

CWD

ACT

Change working directory on the remote system.

CDUP

ACT

Change to parent directory.

SMNT

ACT

Used to mount a different file system.

REIN

ACT

Reinitialize . This flushes all user account and I/O data and reinitializes the connection. Typically, another USER command is then used to start a new session.

QUIT

ACT

This is the logout command to end a session.

PORT

TPC

Used to specify a host data port other than the default.

PASV

TPC

Communicate in Passive mode. This command causes the server to listen on a specified port other than the default.

TYPE

TPC

The data representation type (that is, ASCII, IMAGE, and so on). A numerical value is used for each type.

STRU

TPC

File structure. F = file (no record structure), R = record structure, P = page structure. The default is file.

MODE

TPC

Transfer mode. S = stream, B = block, C = compressed.

RETR

FSC

Retrieve. Instructs the server to send a file.

STOR

FSC

Store. Instructs the server to receive and store a file.

STOU

FSC

Similar to STOR but creates a unique filename on the server.

APPE

FSC

Append with create. If the file exists on the server, data is appended. If not, a file is created.

ALLO

FSC

Used to allocate space before file transfer.

REST

FSC

Restart. Restarts the file transfer at a specified checkpoint.

RNFR

FSC

Rename from. The old pathname of a file that is being renamed . Followed by an RNTO command.

RNTO

FSC

Rename to. Specifies the new pathname of a renamed file.

ABOR

FSC

Instructs the server to abort the previous command and/or data transfer.

DELE

FSC

Deletes a file on the server.

RMD

FSC

Remove directory. Removes a directory on the server.

MKD

FSC

Make directory. Creates a directory on the server.

PWD

FSC

Displays the name of the current directory (print working directory).

LIST

FSC

Lists information about a file or lists files in a directory.

NLIST

FSC

Name list. Sends the client a list of just the names in a directory.

SITE

FSC

Site parameters. Implementation dependent.

SYST

FSC

Sends the client a reply indicating the operating system of the server.

STAT

FSC

Causes the server to return a status response.

HELP

FSC

What it says!

NOOP

FSC

No-operation. Causes the server to send an OK reply.

As you can see from this table, there are many commands that the client side can use to control file transfers. In the next section we will look at the replies that the FTP server can send in response to these commands. Remember, these are the commands used in the protocol exchange. The replies in the next section are not manually entered by a user at a keyboard. They are the replies sent by the FTP server in answer to the protocol commands of the FTP client.

Server Replies to FTP Commands

In the FTP protocol, every command must be followed by a reply from the server. In some cases, more than one reply will be sent to the client. The actual reply is a three-digit number, but it is transmitted as text characters. Following this number is usually some variable-length text. The numerical value is used by the program, and the text is intended for the user of the FTP client. Because some of the text is configurable, you can expect to see different text for the same numerical reply from one implementation to another. For example, you can usually specify the text that is displayed on the client when the user first logs in to your server.

To reply to the client, the three characters representing the numeric reply code are sent, followed by a minus sign ( “) or space character and then the reply text. A simple convention is used for multiline text messages. The first line contains the three-letter numerical code followed by the “ character and then the text. The last line replaces the “ character with the space character. By matching up the two three-digit codes, the client can determine the beginning and ending of a particular multiline message.

Reply Codes

Each of the actual digits that make up the reply code is significant. If you've ever wondered why all those text lines start with numbers , you'll find their meaning in this section. The text displayed will vary from one vendor to another, but the codes should still be implemented for the same general reply condition.

The first digit indicates success or failure:

  • A value of 1 indicates a Positive Preliminary reply, which means that the function requested by the client has been started.

  • A value of 2 is the Positive Completion reply, which means that the requested function was successfully performed.

  • A value of 3 is the Positive Intermediate reply, indicating that the command was received by the server but has not been executed. The server might be waiting for further information.

  • A value of 4 indicates a Transient Negative Completion reply. This means that a temporary error situation has prevented the function requested by the client from being performed.

  • A value of 5 in the first position is the Permanent Negative Completion reply. This indicates that the requested action was not performed. Unlike the Transient message code, the user is not encouraged to retry the command.

The second digit is used to place message types into groups:

  • A value of 0 refers to a syntax error.

  • A value of 1 is an informational message.

  • A value of 2 indicates that the reply refers to either the control or the data connection.

  • A value of 3 is used for replies regarding authentication and accounting, such as during the initial logon process.

  • A value of 4 is unspecified at this time.

  • A value of 5 means that the reply refers to the status of the file server's file system as it relates to the user request.

The third digit in the response code is used to further divide the replies based on the categories indicated by the second digit.

In Table 26.2, you can see the recommended reply codes, in numerical order, as specified in RFC 959.

Table 26.2. FTP Numerical Reply Codes

Code

Description

110

Restart marker reply.

120

Service ready in nnn minutes.

125

Data connection is already open , the transfer is starting.

150

File status okay ”about to open data connection.

200

Command okay.

202

Command not implemented.

211

System status or a help reply text.

212

Directory status.

213

File status.

214

Help message.

215

System type.

220

Service is ready for new user.

221

Service closing the control connection.

225

Data connection is open but no transfer is in progress.

226

Closing the data connection, and the requested function (such as file transfer) is complete.

227

Entering passive mode.

230

User logged in.

250

Requested file action is okay and has been completed.

257

The requested pathname has been created.

331

Username is okay but password is needed.

332

An account name is required to complete the logon.

350

The requested file action is waiting for further information.

421

Service is not available. The control connection is being closed.

425

Unable open data connection.

426

Connection closed ”transfer aborted.

450

Requested file action was not taken.

451

Requested action aborted due to local processing error.

452

Requested action not taken due to insufficient storage space.

500

Syntax error. The command was not recognized (or line too long).

501

Syntax error in parameters or arguments to command.

502

Command not implemented.

503

Incorrect sequence of commands.

504

Command not implemented for a particular parameter.

530

User not logged in.

532

Need account for storing files.

550

Requested action not taken. Usually file not found or access denied .

551

Requested action aborted: page type unknown.

552

Requested file action aborted due to storage allocation exceeded.

553

Requested action not taken. Filename not allowed.

Using a Windows FTP Command-Line Client

Client implementations can vary from simple command-line interfaces to programs that enable you to drag and drop using a graphical interface. All Windows client operating systems, from 98 to XP, provide a default FTP client that works from the command line. The syntax for the Windows XP Professional FTP client is simply the command FTP followed by the server to which you want to connect. The complete syntax for the command is

  ftp  [-  v  ] [-  n  ] [-  i  ] [-  d  ] [-  g  ] [-  s:   filename  ] [-a] [-A] [-w:  windowsize  ] [  hostname  ] 

where

  • - v ” This parameter suppresses responses from the remote server.

  • -n ” The Windows FTP client automatically prompts you for a username and password. This option suppresses these prompts. You are presented with the ftp> prompt and allowed to use the USER command to specify your logon username.

  • -i ” This turns off prompting that occurs when transferring multiple files with the MGET or MPUT command. This is the same function performed by the PROMPT command when you're at the ftp> prompt.

  • -d ” Enables debugging the FTP session. All commands (the actual protocol commands) sent between the client and server are displayed.

  • -g ” Disables filename globbing. When globbing is turned on, you can use wildcards (asterisk and question mark) in filenames. This option forces you to use the exact path and filename.

  • -s: filename ” The commands found in the file named filename are executed after the FTP command line is entered.

  • -a ” Indicates that any local interface can be used when binding the data connection.

  • -A ” Performs an anonymous logon to the FTP server.

  • -w: windowsize ” Specifies the transfer buffer size. The default is 4,096 bytes.

  • hostname ” The hostname or IP address of the remote server.

You can also just enter the command ftp and enter a state called interactive mode. During interactive mode, you will see the prompt ftp> at which you can enter commands. These include some of the same options you can enter on the command line and additional commands that can be used to transfer files, list directories, and so on. The following commands are available with the Windows XP client:

  • ! command ” Yes, it's an exclamation point. Used with no command, this causes you to exit to the "shell," which on a Windows system is the command prompt. After you have performed any tasks that you need to, you can type exit to return to the current FTP session. This command enables you to escape temporarily to check execute commands on the local system without being forced to terminate the FTP program. Alternatively, you can enter a command (separated by a space from the exclamation character) and the program will execute the command on the local system and remain the FTP client program.

  • ? or help ” Typing ? prints a list of commands available. The word help followed by a command gives you local help text for that command.

  • append filename filename ” Appends data to an existing file.

  • ascii ” Sets the transfer type to ASCII (default).

  • bell ” Toggles on or off a bell that sounds after each file transfer. The default is off.

  • binary ” Sets the file transfer type to binary for image files.

  • bye ” Exits the client and ends the current FTP connections.

  • cd directory ” Changes the working directory on the remote FTP server.

  • close ” Closes the current connection and leaves you in the ftp> interpreter prompt so that you can continue to perform other actions, such as open another server.

  • debug ” Similar to the -d command-line option; causes the protocol messages exchanged between client and server to be displayed, prefixed with the characters - - - > .

  • delete filename ” Deletes a file on the remote server.

  • dir ” Lists files and directories on the remote server. You can follow this command with a wildcard to narrow your listing, provided that globbing is turned on.

  • disconnect ” Disconnects the session with the current server, leaving you in the FTP interpreter prompt to continue working.

  • get filename ” Is used to get a single file from the remote server.

  • glob ” Toggles (as does the -g command-line option) for globbing filenames. This is a simple way to say that you can use wildcards in local filenames and pathnames, and it is the default.

  • hash ” What you used to eat in the Army. Actually, this command causes a hash mark (more correctly called the number-sign character) to be printed for every 2,048 bytes transferred. This is helpful in a long transfer because you can watch the progress and determine whether it has stalled or stopped .

  • lcd pathname ” Changes the working directory on the client's local system. Compare to CD , which changes the working directory on the remote server's system.

  • literal text ” Sends text, verbatim, to the server. A single response is expected back.

  • ls ” Displays an abbreviated listing of the files or directories on the remote server system. Similar to the dir command.

  • mdelete filenames ” Is used to delete more than one filename on a remote server. You can use wildcards for this if needed (check that globbing).

  • mdir ” Displays a listing of files and directories that exist on the remote sever.

  • mkdir directoryname ” Creates a new directory (or subdirectory) on the remote server.

  • mls ” Displays an abbreviated listing of the files and directories that exist on the remote server.

  • mput filenames ” Performs multiple file transfers from the client to the server, using only one command. Wildcards can be used.

  • open hostname ” Is used to connect to a specific server after the FTP interpreter prompt has been issued.

  • prompt ” Is used to toggle on or off prompting during multiple file transfers. The default is on. This means that if you use mget , mdel , or mput to work with files, you'll get prompted for each file. Toggle this off if you want to work with a large number of files and let it just run without having to answer Y or N to each prompt for each file.

  • put filename ” Transfers a single file to the remote FTP server from the client.

  • pwd ” Stands for Print Working Directory. This displays the current directory on the remote FTP server.

  • quit ” Exits the FTP client and ends any outstanding connections.

  • quote ” Same function as the literal command.

  • recv ” Same as the get command.

  • remotehelp ” Displays help from the remote server.

  • rename filename filename ” Renames a file on the remote FTP server.

  • rmdir directory ” Removes a directory on the remote FTP server.

  • send filename ” Same as the put command.

  • status ” Toggles on or off a status display.

  • trace ” Toggles on or off a display showing the routes taken by each packet.

  • type type ” Sets the current transfer type. Examples: type ascii (for text files) or type binary (for program files).

  • user username ” Is used to specify a username during the logon process.

  • verbose ” Toggles on or off verbose mode. The default is on, so all replies sent by remote server are displayed.

As you can see, many commands duplicate functions performed by others. Over the years, commands have been added that are easier to remember. For example, you'll find that some of the commands supported by Linux are different than Windows FTP clients.

Note that there are usually two commands to perform file functions, depending on whether you are operating on one or multiple files. For example, use GET filename to get a single file, but to get multiple files, use MGET filename in a format such as MGET REPORTS*.* . Don't forget that, when using the "M" (multiple) commands, you might want to first issue the PROMPT command to turn interactive mode off. Otherwise, you will be prompted before downloading each file and have to enter Y or N. Conversely, you can leave prompting turned on if you know you want to retrieve most of the files that match your file specification but want to exclude a few by answering no to the prompts.

In the following listing, you can see how the command is invoked to connect to the remote server, the reply messages received from the server, and a directory listing produced by using the DIR command. Next, the ls command is used to show the difference in the output. Finally, the session is set to show hash marks ( hash ) and then set to do a binary download ( binary ). You can see the results of using the HASH command and then the GET command to retrieve a file from the remote server.

 J:\>ftp ftp.twoinc.com Connected to ftp.twoinc.com. 220-ArGoSoft FTP Server for WinNT/2000, Version 1.2 (1.2.1.1) 220-Welcome to Active Web Hosting 220-For more information on our 220-services please call 220 (800) 946-7764 or (702) 451-1577. User (ftp.twoinc.com:(none)): twoinc.com 331 User name OK, need password Password: 230 User twoinc.com logged in successfully ** ftp> dir 200 Port command successful 150 Opening binary data connection drw-r--r--  1 user   group      0 Mar 06 00:00 .. -rw-r--r--  1 user   group     436 Feb 24 13:36 cnt.htm -rw-r--r--  1 user   group     455 Feb 24 13:36 default.htm -rw-r--r--  1 user   group     949 Feb 24 13:36 default.html -rw-r--r--  1 user   group     807 Feb 24 13:36 emp.htm -rw-r--r--  1 user   group   1729597 Mar 06 09:52 hiroshimamontage.mp3 -rw-r--r--  1 user   group     268 Feb 24 13:36 lnk.htm drw-r--r--  1 user   group      0 Jan 26 12:56 logs -rw-r--r--  1 user   group    1969 Feb 24 13:36 pub.htm -rw-r--r--  1 user   group    1317 Feb 24 13:36 who.htm 226 Transfer complete ftp: 807 bytes received in 0.15Seconds 5.38Kbytes/sec. ftp> ls 200 Port command successful 150 Opening binary data connection .. cnt.htm default.htm default.html emp.htm hiroshimamontage.mp3 lnk.htm logs pub.htm who.htm 226 Transfer complete ftp: 147 bytes received in 0.05Seconds 2.94Kbytes/sec. ftp> hash Hash mark printing On ftp: (2048 bytes/hash mark) . ftp> binary 200 Type set to Image (binary) ftp> get hiroshimamontage.mp3 200 Port command successful 150 Opening binary data connection ############################################################################# ############################################################################# ############################################################################# ############################################################################# ############################################ 226 Transfer complete ftp: 1729597 bytes received in 573.14Seconds 3.02Kbytes/sec. ftp> 

As you can see, using the FTP utility is an easy way to examine directory information on remote systems or to exchange files.

Using Red Hat Linux FTP

Red Hat Linux Version 8.0 offers both a GUI FTP client and a command-line client. If you choose to install the server version of Red Hat Linux, you will also find an FTP server. In Figure 26.2 you can see an example of the GUI version. To start up the GUI FTP client, click on the Red Hat symbol (it's in the same place as the Start button on Windows systems), Extras, Internet, and then gFTP.

Figure 26.2. Red Hat Linux offers a GUI FTP client.

graphics/26fig02.jpg

From Figure 26.2 you can see that the GUI FTP client allows you to enter the destination location (Host = ftp.archive.org) and also lets you use the CD (change directory) command to get to the target directory ( /pub/movies/mpeg2 ). From this directory you simply double-click on the file to download. The lower portion of the window shows the progress being made (the number of total bytes for the file, and the number of bytes transferred so far). At the very bottom of the window, you can see the actual FTP commands that are used during this session. These can be just as useful as those from a command-line client when you're trying to determine what has gone wrong during troubleshooting efforts. Also notice that on the right side of the window you can see the files available in the local directory (in this case the root directory, which you shouldn't use unless you know what you are doing!).

Tip

Because this GUI client is so easy to use, it is the preferred method for those who are just now learning how to use Linux. One important thing to note here is that, unlike with Windows, there are several graphical user interfaces, usually referred to as desktops in the Unix/Linux community. In the example shown in Figure 26.2, you are seeing the Gnome desktop. Another popular desktop is the KDE desktop. Depending on the company from which you obtain your Linux system, you may find one of these, both of these, or other desktops. Some even allow you to use one desktop while listing accessories from the other desktops installed on the system! Additionally, Linux itself is just an operating system. The applications, such as the GUI FTP client described here, are open-source applications that Red Hat decided to ship with its version of Linux. With other Linux vendors , your mileage may vary, as the saying goes.

Using the Red Hat Linux Command-Line FTP Client

Just about every operating system in existence today offers, just as Windows does, a command-line version of the FTP client. Although a GUI version is usually easier to use, the command-line version offers specific capabilities (as you learned earlier about the Windows version) that can be incorporated into script files. For those who are used to using a command-line version, you'll find it in Linux also. If you are trying to automate the transfer of a file (such as a report or data file created by an application) to another system, then the command-line version is the choice to make. You could manually use the GUI version, but if you use the command-line version, the process can be automated. Simply check the log file to ensure that the file has successfully been transferred to (or from) the other system.

Note

In the FTP syntax listing for Linux, keep in mind that unlike some other operating systems, Linux is case-sensitive. That is, a -a is not the same as a -A . And the command ftp is to be entered, not FTP . Other commands, such as quit , will not work if capitalized. You will find that many Unix/Linux utilities use the same alphabetic characters in the same utility, and it is the case of the character that makes the difference. And don't forget filenames! If you attempt to send a file from a Unix/Linux system that is named myfile , you'll get an error (file not found) when trying to send MYFILE or MyFile .

The syntax of the Red Hat Linux command-line version of the FTP client is

 ftp [-v] [-d] [-i] [-n] [-g] [-k  realm  ] [-f] [-x] [-u] [-t]  hostname  

where

  • -v ” Invokes the verbose option, which makes the FTP client show all responses that the remote server sends. Also displays the statistics of the session.

  • -d ” Displays debugging for troubleshooting purposes.

  • -i ” For multiple file transfers, such as filenames specified with a wildcard, this option will prevent the ftp utility from prompting you (Y or N) for each file.

  • -n ” This command prevents ftp from attempting an autologin to the remote server. The file named . netrc in the user's home directory is checked to see whether authentication is necessary. Otherwise, you will be prompted for authentication credentials when logging in to a remote server.

  • -g ” As described in the previous syntax for Windows, prevents globbing.

  • -k realm ” This is used when Kerberos authentication is used. This command will obtain the authentication tickets valid for the Kerberos realm.

  • -f ” This option causes authentication credentials to be forwarded to the remote computer.

  • -x ” The encryption procedures will be negotiated with the remote host after a successful authenticated login.

  • -u ” Causes the client to negotiate authentication methods with the remote system. The AUTH command, as described earlier in this chapter, is used instead.

  • -t ” This option enables packet tracing for the session.

  • hostname ” This is the DNS hostname, or the IP address that you want to connect to using ftp.

Similar to the Windows version, if you simply enter ftp for the Red Hat command utility, you will enter a command-line interpreter mode in which you can issue commands interactively. Most of the commands you can enter in interactive mode are the same as the Windows versions. Following is a list of additional commands provided by the Red Hat ftp command-line utility in interactive mode.

  • account [ password ] ” Used to enter a second password after the initial logon if the server computer requires it. If you just enter account , you will be prompted for the password.

  • case ” This command toggles on/off filename case mapping. When off, which is the default, filenames from remote systems that use uppercase letters are converted to lowercase letters when a file is transferred to the client.

  • cdup ” Similar to cd , this command changes the current directory on the remote server. The working directory is set to the parent directory of the current working directory.

  • chmod mode filename ” This change mode command is used to alter the permissions ( mode ) of the remote filename , provided you have the right to do so.

  • cr ” For ASCII file transfers, this command toggles on/off the stripping of carriage-return (CR) characters. Some operating systems, such as Windows, use a CR/LF ( linefeed ) character to denote the end of a text record. Unix and Linux use just the LF character. When toggled on, the CR character is removed. Otherwise, both CR and LF are left in the file retrieved from the server.

  • debug ” Toggles debug mode on/off. When on, commands sent to the remote server are printed, preceded by the ---> text string.

  • help command ” Provides a short help text message for command .

  • idle seconds ” Sets the inactivity timer on the server (after which a disconnection can occur). When it's used without seconds being specified, the current inactivity timer value is displayed.

  • macdef macroname ” Used to define a macro, which is a set of commands to be executed. See help text for information on defining macros in FTP.

  • mode modename ” Sets the default transfer mode to modename . The default is stream mode.

  • modtime filename ” Displays the time a file on the remote server was last modified.

  • newer filename ” If the modification time on a remote file is newer than a file of the same name on the client, the newer file is retrieved from the server. If the file does not exist on the client, the remote file is retrieved.

  • reget ” Similar to the get command, this command will check to see whether a file with the same filename exists on the local machine. If so, and if the file is smaller than the same file on the remote server, then it is assumed that a previous file transfer was interrupted , and the reget command restarts the transfer from the point where it stopped. Useful for transferring large files.

  • restart marker ” Similar to reget , this restarts an interrupted transmission. For most Unix/Linux systems, marker is a byte offset into the file indicating where the file transfer should be resumed.

  • runique ” Useful when retrieving files that have the same names as existing files on the client. Instead of replacing the file, a number in the format of " .1 " is attached to the filename, with a possible total of 99 versions of the file. runique toggles this behavior on/off.

  • size filename ” Gets the size of a remote file.

  • sunique ” Similar to the runique command, causes unique filenames to be used on a remote system when the name of the file being sent already exists on the remote server. The remote server must support this command.

  • system ” Returns the operating system running on the remote server.

  • tenex ” Sets the file transfer to a type used to exchange data with a TENEX machine.

There are other commands available in interactive mode, such as those related to security. Use the help command interactively to learn about these and other commands that are not often used.

The Trivial File Transfer Protocol (TFTP)

This protocol was developed to be a "lite" version of FTP, where security and elaborate mechanisms for error control were not needed. Generally, TFTP is used to download operating systems, firmware upgrades, and other files to network devices or diskless workstations. For example, a diskless workstation can use BOOTP (or DHCP) to obtain IP configuration information and the location of a TFTP server, along with the name of the file to download. For more information about BOOTP and DHCP and how they allow diskless workstations to obtain the information they need in order to boot, see Chapter 29, "BOOTP and Dynamic Host Configuration Protocol (DHCP)."

No authentication is used, so this is a service that should be used only where it is absolutely needed. The syntax for the TFTP command is

 tftp [-i]  host  [get  put]  source  [  destination  ] 

The command-line option -i specifies a binary image transfer, which is precisely the kind of transfer for which this utility is usually used. If you omit this option, an ASCII file transfer is done by default.

The get command specifies that the source file is to be transferred from source to destination . The put command works, just as in FTP, in the opposite direction to send a file from the client to the TFTP server.

The following are other important differences between FTP and TFTP:

  • FTP uses TCP, whereas TFTP uses UDP.

  • Only file transfers are supported. Directory listings, file deletions, and other features of FTP are not implemented in TFTP.

  • TFTP was designed to be simple and compact so that its code could be stored in a small amount of read-only memory, making it an ideal solution for implementation in device firmware.

The official specification for TFTP can be found in RFC 1350, "The TFTP Protocol (Revision 2)." It uses a simple set of messages to establish the file exchange. In each message, the first 2 bytes are reserved for use as an opcode. Five message types are used:

  • 1 ” This opcode (RRQ) is used to initiate a read request to download a file from the TFTP server to the client. After the first 2-byte opcode, a variable number of bytes specifying the filename follows and is terminated with a zero byte. Following this is the mode used for the transfer. This can be the text netascii , which means that the transfer will consist of ASCII text lines terminated by the carriage-return/line-feed combination. The text octet in the mode field indicates that the data transfer will be a simple transfer of 8-bit octets of data.

  • 2 ” This opcode (WRQ) is similar to the first one, except that the file transfer will be made from the client to the TFTP server.

  • 3 ” This opcode (data) is used to send a block of data. The 2-byte opcode is followed by a 2-byte field that contains a block number. Following this is from 0 to 512 bytes of actual data.

  • 4 ” This opcode (ACK) acknowledges the block transferred. Each block is acknowledged. The format for this packet is the 2-byte opcode followed by the 2-byte block number being acknowledged by the receiver.

  • 5 ” This opcode (error) is reserved for reporting errors. The 2-byte opcode is followed by a 2-byte error code and a variable-length error message terminated by a zero byte. Note that, for most error types, the connection is aborted and must be tried again.

The interoperation of this protocol is quite simple. For each block sent, an acknowledgment is sent back to the sender. This is sometimes called a stop-and-wait protocol. Remember that TCP uses an acknowledgment mechanism in which one ACK can acknowledge multiple segments of data. In TFTP, each block is acknowledged.

Block numbers are numbered starting at 1. However, for a write request, the acknowledgment number returned to the sender is a zero because a data block has not yet been exchanged.

Termination of the file transfer is also simply done. When a block that has less than 512 bytes of data in it is received, the file transfer has finished. Because UDP is used instead of TCP, the TFTP client/server software must implement its own retransmission technique for blocks that get lost or damaged in the network. Again, to make the protocol as simple as possible, no checksum is calculated on the TFTP messages. Instead, the simpler methods used by UDP are depended on to catch any errors.

Ports used by TFTP are allocated on a client-by-client basis. When the TFTP server receives the first client request message on its well-known TFTP port of 69, the server then allocates another port for use and communicates this back to the client. The client can continue to use a port on its side of the connection. However, from that point on it uses the newly assigned port it received from the TFTP server as the server host port. This feature allows a TFTP server to service multiple requests from different clients. The well-known port of 69 is used only for the initial communication.



Upgrading and Repairing Networks
Upgrading and Repairing Networks (5th Edition)
ISBN: 078973530X
EAN: 2147483647
Year: 2003
Pages: 434

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net