Windows IT Pro
Windows IT Library
  - Advertise        
Windows IT Pro Logo

  Home  |   Books  |   Chapters  |   Topics  |   Authors  |   Book Reviews  |   Whitepapers  |   About Us  |   Contact Us

search for  on    power search   help
 






File Transfer Protocol Services
View the book table of contents
Author: Tony Northrup
Published: July 1998
Copyright: 1998
Publisher: IDG Books
 


TYPICAL DIALOG OF A WEB BROWSER
This section shows a sample dialog between an FTP client and server. Specifically, the client is Netscape Navigator 4.0, the most popular Web browser at the time of this writing. Those running anonymous FTP sites on the public Internet need to understand exactly what will happen in this dialog, as it may happen literally thousands of times in a day, depending on what your business is. A Netscape browser initiated this dialog, but other browsers operate in a very similar fashion.

While reading through this dialog, pay particular attention to the different commands the client passes to the server (always the first word the client transmits, and always in all uppercase) and to the various messages the server returns to the client. The only significant parts of the messages being returned to the client are the numeric codes. Remember, all lines are ended with a carriage return and a line-feed (CR/LF).
Client > <Initiates TCP connection to Server's port 21>
Server> 220 ftp Microsoft FTP Service
Client> USER anonymous
Server> 331 Anonymous access allowed, send identity
Client> PASS mozilla@
Server> 230-This is FTP.MICROSOFT.COM
Server> 230-Please see the dirmap.txt file for
Server> 230-more information ( ... )
This completes the user logon portion. The 220 server message is simply a greeting to the client that indicates the server is ready for a logon request. The client requests anonymous access by submitting the command USER with the argument anonymous. The server returns a 331 message, indicating that the username was received successfully, and includes a text message that some clients may display to the user (Navigator, however, does not). This prompts the client to return a password–in this case, the generic mozilla@. The 230 messages returned by the server contain a welcome message, which Navigator displays to the user.
Client> REST 0
Server> 350 Restarting at 0.
Client> SYST
Server> 215 Windows_NT version 4.0
Client> PWD
Server> 257 "/" is current directory.
The REST, SYST, and PWD commands are part of Navigator’s normal communication setup. Most FTP clients issue several commands at the beginning of a session to ensure that transfer defaults do not vary from server to server. REST is a command used to pick up a session after an error caused it to end–REST 0 is simply Navigator’s way of restarting any session that may have been previously active. The SYST command queries the server to determine what operating system it is running. Presumably, this information is used somewhere inside of Navigator, but I cannot imagine what it could be used for since it does not indicate what type of FTP service the server is running. The PWD (Print Working Directory) command queries the server for the current working directory, and the server returns whatever the default directory is, in this case, “/.” Remember that the FTP directory does not necessarily correspond to a directory on the server’s file system.
Client> PASV
Server> 227 Entering Passive Mode (198,105,232,1,15,47)
At this point, the client opens a data connection to the server.
Client> TYPE I
Server> 200 Type set to I
Client> SIZE /
Server> 500 'SIZE /': command not understood
Client> MDTM /
Server> 500 'MDTM /': command not understood
Client> CWD /
Server> 250 CWD command successful.
Client> LIST
Server> 125 Data connection already open; Transfer starting
Once again, a data connection is opened to allow data to be transferred to the client. Notice that the client has issued the LIST command–this asks the server to transfer a listing of files in the current directory. Once the data has been transferred, the 226 message is returned to the client, and the client will break the TCP connection. This completes the dialog setup between the client and the server.


FTP SERVICES

This section covers the actual commands and responses exchanged between FTP clients and servers. The information contained in this section is very detailed and critical to anyone performing network analysis on the FTP protocol, anyone who writes FTP clients or servers, or anyone who scripts FTP communications.

Terminology
The term DTP refers to the data transfer process, the method used to control the data transfer connection.

The term PI refers to the protocol interpreter. You will see the terms “server-PI” and “user-PI.” The server protocol interpreter is the process listening on TCP port 21 on the FTP server. It must be able to respond to standard FTP commands such as USER and PASS. The server-PI has control over the server-DTP. The server-PI uses the server-DTP to transfer data to the user. The user-PI is typically a client-side application that knows how to speak the FTP protocol. The user-PI controls the user-DTP.

Common Commands
The commands listed in this section are probably all the FTP commands you need to know. Each one of these commands is commonly used by FTP clients and should be supported in some fashion by all FTP servers.

USER (USER NAME)
All FTP communications begin with the USER command. This command takes a single argument: the username the client wishes to be authenticated with. In a Windows NT environment, this may include both the domain name and the username. For example, when logging onto an NT server that is a member of a domain, the client may transmit the command:
USER domain\username
The most common argument to the USER command is anonymous. Anonymous logons to FTP are common on the Internet, where a large percentage of FTP servers carry information for the general public.

PASS (PASSWORD)
Generally the second command transmitted by a client to the server, the PASS command carries as an argument the password for the user already specified by the USER command. This command really is as simple as it seems: There is no encoding or encryption of the password, it is simply clear text. An example of transmitting a password from a client to a server:
PASS elvislives
Analyzing the USER Command for Problems
A common problem with some FTP clients and FTP proxy servers occurs when issuing the USER command. Many do not handle the backslash character correctly; they may translate it into a forward slash or omit it completely. I have even seen a case in which an FTP client translated it into two backslashes, Perl-style.

CWD (CHANGE WORKING DIRECTORY)
The CWD command changes the directory the FTP server is working with. The sole argument for this command is the new directory, in either absolute form or relative form. Examples of both of these forms are given here:
CWD /usr/root
CWD /usr/root/
CWD documents
The first command changes the current directory to /usr/root, regardless of what the current directory is. The second command illustrates an optional slash at the end of the directory name. The third command moves into a child directory of the current directory named documents; it only works from directories that have a subdirectory named documents.

QUIT (LOG OUT)
The QUIT command is sent to the server to indicate that the FTP session is over. This command takes no arguments.

RETR (DOWNLOAD)
When the RETR command is issued from the client, a data transfer connection is established. The RETR command takes as an argument the path to the file to be transferred. For example, to use the RETR command to transfer the file /documents/file.html, issue the command:
RETR /documents/file.html
STOR (UPLOAD)
Similar in function and execution to the RETR command, the STOR command sends a file from the client to the server. The only argument for the STOR command is the destination location on the server. If the file already exists in the destination directory, it is automatically overwritten. To upload the file file.html to the /documents directory, issue the command:
STOR /documents/file.html
REST (RESTART) The REST command is used to continue a session that has been interrupted. The REST command has an argument, an integer, that represents the position in the file where transfer should begin. For example, to restart a transfer at byte 4096 in a file, the client would issue the following commands to the server:
REST 4096
RETR /documents/file.zip
It is important to understand that the command that follows the REST command must be a transfer of some kind, either a STOR or a RECV.

RNFR, RNTO (RENAME FROM, RENAME TO)
The RNFR and RNTO commands always work together. Rather than issuing two arguments to a single command, as with the MS-DOS command rename file1.txt file2.txt, the rename function is broken into two individual commands. For example:
Client> RNFR file1.txt
Server> 350 File exists, ready for destination name
Client> RNTO file2.txt
Server> 250 RNTO command successful.
These two commands must always be used together.

ABOR (ABORT)
The ABOR command cancels any command that is currently being executed on the server. If data is currently being transferred in a data session, it is cancelled. This command takes no arguments.

DELE (DELETE)
The DELE command removes a file on the server, assuming the user has the appropriate permissions. It takes a single argument: the relative or absolute path to the file to be removed. For example, the following command will remove the file /documents/file.htm from the server:
DELE /documents/file.htm
Servers That Support Broken Downloads
Many servers, including the FTP service included with IIS 3.0, do not support restoring broken transfers. To determine whether a server is capable of restoring connections, try issuing a REST command with a nonzero argument. Servers that do not support the REST command will return an error (such as “504 Reply marker must be 0”). Though IIS 3.0 allows the command REST 0 to be issued, it only allows the argument to be zero–which does not really do any good. It is included simply for compatibility.

RMD (REMOVE DIRECTORY)
The RMD command is similar to the DELE command, except that it removes an empty directory instead of a file. To remove the directory documents, first make sure that it contains no files whatsoever. Then issue the command:
RMD /documents
Please note that the RMD command does not let you remove virtual directories created on an IIS server, only physical directories.

MKD (MAKE DIRECTORY)
To create a directory on an FTP server, issue the MKD command with either a relative or absolute path given as the only argument. The path given must include only a single directory that does not yet exist. For example, you cannot issue the MKD command to create two nested directories at once. To create the directory production within the already existing documents directory, you would issue the command:
MKD /documents/production
PWD (PRINT WORKING DIRECTORY)
The client uses the PWD command to determine the current active directory on the server. The active directory is the default location for all commands that do not include an absolute directory path. In theory, this would only be necessary when a client first establishes a connection to the server; after that, file system navigation is up to the client, so the client should be able to compute its working directory from the commands it issues to the server. This command takes no arguments and forces the server to return a 257 message with the directory path listed as an argument.

LIST (DIRECTORY LISTING)
The LIST command causes a data transfer to occur that will contain the directory listing for the current working directory. An absolute or relative path can be given as an optional argument if a directory listing for another directory is desired.

SYST (EXECUTE SYSTEM COMMAND)
The SYST command is used to determine what operating system the remote FTP server is running. It does not tell you what specific FTP service it is running, which is more useful information. The SYST command takes no arguments.

NOOP (NO OPERATION)
This command does nothing except stall the remote server. In many cases, the remote FTP server will close the connection after a certain amount of time has passed with no activity from the client. The NOOP command can be issued to reset this time-out value. Please note that not every Web server will respond the same way: Many will simply ignore the command and will not reset the time-out value.



Page: 1, 2, 3

next page



ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Critical Challenges of ESI & Email Retention
Are you storing too much electronic information? Get expert legal advice and better understanding of what you are required to do as an IT professional.

Become a fan of Windows IT Pro on Facebook!
Join us on Facebook and be a fan of Windows IT Pro!

Sustainable Compliance: Are You Having a Resource Crisis?
Read this white paper to examine trends in compliance and security management and review approaches to reducing the cost and operational burden of compliance.

Rev Up Your IT Know-How with Our Recharged Magazine!
The improved Windows IT Pro provides trusted IT content with an enhanced new look and functionality! Get comprehensive coverage of industry topics, expert advice, and real-world solutions—PLUS access to over 10,000 articles online. Order today!

Get It All with Windows IT Pro VIP
Stock your IT toolbox with every solution ever printed in Windows IT Pro and SQL Server Magazine plus bonus Web-exclusive content on hot topics. Subscribe to receive the VIP CD and a subscription to your choice of Windows IT Pro or SQL Server Magazine!



Order Your Fundamentals CD Today!
Gain an introduction to Exchange, learn server security requirements, and understand how unified communications can play a role in your messaging strategies with this free Exchange CD.
Windows IT Pro Home Register About Us Affiliates / Licensing Media Kit Contact Us/Customer Service  
SQL Connected Home IT Library SuperSite FAQ Wininfo News
Europe Edition Office & SharePoint Pro Windows Dev Pro Windows Excavator 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing