start page | rating of books | rating of authors | reviews | copyrights

Book HomeJava and XSLTSearch this book

Chapter 18. FTP

Contents:

The FTP Protocol
Net::FTP
FTP Configuration with Net::Netrc

The File Transfer Protocol (FTP) is a popular means of transferring files between computers. FTP communication follows the client/server model: the client initiates a conversation by sending commands, and the server responds with messages and status codes, as well as by sending or receiving files. This chapter discusses two FTP-related modules included in the libnet distribution: Net::FTP, which provides a number of wrapper functions for implementing the client side of FTP, and Net::Netrc, which provides an interface for getting information from a .netrc file.

The FTP protocol permits two-way file transactions, in which files can be sent to or taken from an FTP server. These transactions involve the local filesystem (on the client side) and the remote filesystem (on the server side). When a file is transferred between the local and remote systems, its filename on the destination system is the same as on the source system, unless you specify a new filename.

The FTP protocol also lists the types of files that can be transferred. These types define (among many other things) how end-of-line characters are handled for different types of files.

18.1. The FTP Protocol

When a server accepts FTP requests, it opens a port (generally port 21) for incoming connections and authenticates clients based on account or anonymous privileges. A user may log in with a legitimate account on that machine, provide her own password, and access any file she normally has access to under the Unix shell. Many servers also allow "anonymous" FTP, in which users log in with the name "anonymous" and use their email address as the password. They are then granted restricted access to a limited portion of the filesystem.

The FTP commands defined in RFC 959 are listed in the following table:

Command

Meaning

ABOR

Abort previous FTP command.

ACCT

Specify the user's account.

ALLO

Tell server to allocate additional storage for new file.

APPE

Tell server to append to an existing file.

CDUP

Change to parent directory.

CWD

Change directory.

DELE

Delete a file.

HELP

Get help.

LIST

List files for display.

MKD

Make a directory.

MODE

Specify the data transfer mode.

NLST

List files for additional processing.

NOOP

No-op.

PASS

Specify the user's password.

PASV

Tell server to go into "passive" mode.

PORT

Specify data port for connection.

PWD

Print working directory.

QUIT

Close connection.

REIN

Reinitialize connection.

REST

Restart a file transfer.

RETR

Retrieve a file.

RMD

Remove a directory.

RNFR

Specify pathname of file to be renamed.

RNTO

Specify new name of file being renamed.

SITE

Provide additional site-specific services.

SMNT

Mount a different filesystem.

STAT

Get status.

STOR

Tell server to accept a file for storage.

STOU

Tell server to create unique name for new file.

STRU

Specify the file structure.

SYST

Tell server to declare its operating system.

TYPE

Specify the data representation type.

USER

Specify the username.

Exactly which FTP commands are available depends on the server; some servers implement a subset, or possibly a superset, of the commands defined in the RFC. Net::FTP, which we'll discuss in this chapter, provides methods that implement all the commands except the following:

ALLO

HELP

MODE

REIN

SITE

SMNT

STAT

STRU

SYST



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.