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.
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 be given access to 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:
Abort previous FTP command
Specify the user's account
Tell server to allocate additional storage for new file
Tell server to append to an existing file
Change to parent directory
Delete a file
List files for display
Make a directory
Specify the data transfer mode
List files for additional processing
Specify the user's password
Tell server to go into "passive" mode
Specify data port for connection
Print working directory
Restart a file transfer
Retrieve a file
Remove a directory
Specify pathname of file to be renamed
Specify new name of file being renamed
Provide additional site-specific services
Mount a different file system
Tell server to accept a file for storage
Tell server to create unique name for new file
Specify the file structure
Tell server to declare its operating system
Specify the data representation type
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:
Copyright © 2001 O'Reilly & Associates. All rights reserved.