MAN page from Old RedHat 6.X libnet-1.0606-1.i386.rpm
Net::FTP
Section: User Contributed Perl Documentation (3)
Updated: perl 5.005, patch 03
Index NAME
Net::FTP - FTP Client class
SYNOPSIS
use Net::FTP; $ftp = Net::FTP->new("some.host.name"); $ftp->login("anonymous","meAATThere.there"); $ftp->cwd("/pub"); $ftp->get("that.file"); $ftp->quit; DESCRIPTION
Net::FTP is a class implementing a simple FTP client in Perl asdescribed in RFC959. It provides wrappers for a subset of the RFC959commands.
OVERVIEW
FTP stands for File Transfer Protocol. It is a way of transferringfiles between networked machines. The protocol defines a client(whose commands are provided by this module) and a server (notimplemented in this module). Communication is always initiated by theclient, and the server responds with a message and a status code (andsometimes with data).
The FTP protocol allows files to be sent to or fetched from theserver. Each transfer involves a local file (on the client) and aremote file (on the server). In this module, the same file namewill be used for both local and remote if only one is specified. Thismeans that transferring remote file /path/to/file will try to putthat file in /path/to/file locally, unless you specify a local filename.
The protocol also defines several standard translations which thefile can undergo during transfer. These are ASCII, EBCDIC, binary,and byte. ASCII is the default type, and indicates that the sender offiles will translate the ends of lines to a standard representationwhich the receiver will then translate back into their localrepresentation. EBCDIC indicates the file being transferred is inEBCDIC format. Binary (also known as image) format sends the data asa contiguous bit stream. Byte format transfers the data as bytes, thevalues of which remain the same regardless of differences in byte sizebetween the two machines (in theory - in practice you should only usethis if you really know what you're doing).
CONSTRUCTOR
- new (HOST [,OPTIONS])
- This is the constructor for a new Net::FTP object. HOST is thename of the remote host to which a FTP connection is required.
OPTIONS are passed in a hash like fashion, using key and value pairs.Possible options are:
Firewall - The name of a machine which acts as a FTP firewall. This can beoverridden by an environment variable FTP_FIREWALL. If specified, and thegiven host cannot be directly connected to, then theconnection is made to the firewall machine and the string @hostname isappended to the login identifier. This kind of setup is also refered toas a ftp proxy.
Port - The port number to connect to on the remote machine for theFTP connection
Timeout - Set a timeout value (defaults to 120)
Debug - debug level (see the debug method in the Net::Cmd manpage)
Passive - If set to a non-zero value then all data transfers will be doneusing passive mode. This is not usually required except for some dumbservers, and some firewall configurations. This can also be set by theenvironment variable FTP_PASSIVE.
If the constructor fails undef will be returned and an error message willbe in $@
METHODS
Unless otherwise stated all methods return either a
true or
falsevalue, with
true meaning that the operation was a success. When a methodstates that it returns a value, failure will be returned as
undef or anempty list.
- login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])
- Log into the remote FTP server with the given login information. Ifno arguments are given then the Net::FTP uses the Net::Netrcpackage to lookup the login information for the connected host.If no information is found then a login of anonymous is used.If no password is given and the login is anonymous then the usersEmail address will be used for a password.
If the connection is via a firewall then the authorize method willbe called with no arguments.
- authorize ( [AUTH [, RESP]])
- This is a protocol used by some firewall ftp proxies. It is usedto authorise the user to send data out. If both arguments are not specifiedthen authorize uses Net::Netrc to do a lookup.
- site (ARGS)
- Send a SITE command to the remote server and wait for a response.
Returns most significant digit of the response code.
- type (TYPE [, ARGS])
- This method will send the TYPE command to the remote FTP serverto change the type of data transfer. The return value is the previousvalue.
- ascii ([ARGS]) binary([ARGS]) ebcdic([ARGS]) byte([ARGS])
- Synonyms for type with the first arguments set correctly
NOTE ebcdic and byte are not fully supported.
- rename ( OLDNAME, NEWNAME )
- Rename a file on the remote FTP server from OLDNAME to NEWNAME. Thisis done by sending the RNFR and RNTO commands.
- delete ( FILENAME )
- Send a request to the server to delete FILENAME.
- cwd ( [ DIR ] )
- Attempt to change directory to the directory given in $dir. If$dir is "..", the FTP CDUP command is used to attempt tomove up one directory. If no directory is given then an attempt is madeto change the directory to the root directory.
- cdup ()
- Change directory to the parent of the current directory.
- pwd ()
- Returns the full pathname of the current directory.
- rmdir ( DIR )
- Remove the directory with the name DIR.
- mkdir ( DIR [, RECURSE ])
- Create a new directory with the name DIR. If RECURSE is true thenmkdir will attempt to create all the directories in the given path.
Returns the full pathname to the new directory.
- ls ( [ DIR ] )
- Get a directory listing of DIR, or the current directory.
In an array context, returns a list of lines returned from the server. Ina scalar context, returns a reference to a list.
- dir ( [ DIR ] )
- Get a directory listing of DIR, or the current directory in long format.
In an array context, returns a list of lines returned from the server. Ina scalar context, returns a reference to a list.
- get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )
- Get REMOTE_FILE from the server and store locally. LOCAL_FILE may bea filename or a filehandle. If not specified the the file will be stored inthe current directory with the same leafname as the remote file.
If WHERE is given then the first WHERE bytes of the file willnot be transfered, and the remaining bytes will be appended tothe local file if it already exists.
Returns LOCAL_FILE, or the generated local file name if LOCAL_FILEis not given.
- put ( LOCAL_FILE [, REMOTE_FILE ] )
- Put a file on the remote server. LOCAL_FILE may be a name or a filehandle.If LOCAL_FILE is a filehandle then REMOTE_FILE must be specified. IfREMOTE_FILE is not specified then the file will be stored in the currentdirectory with the same leafname as LOCAL_FILE.
Returns REMOTE_FILE, or the generated remote filename if REMOTE_FILEis not given.
NOTE: If for some reason the transfer does not complete and an error isreturned then the contents that had been transfered will not be removeautomatically.
- put_unique ( LOCAL_FILE [, REMOTE_FILE ] )
- Same as put but uses the STOU command.
Returns the name of the file on the server.
- append ( LOCAL_FILE [, REMOTE_FILE ] )
- Same as put but appends to the file on the remote server.
Returns REMOTE_FILE, or the generated remote filename if REMOTE_FILEis not given.
- unique_name ()
- Returns the name of the last file stored on the server using theSTOU command.
- mdtm ( FILE )
- Returns the modification time of the given file
- size ( FILE )
- Returns the size in bytes for the given file as stored on the remote server.
NOTE: The size reported is the size of the stored file on the remote server.If the file is subsequently transfered from the server in ASCII modeand the remote server and local machine have different ideas about``End Of Line'' then the size of file on the local machine after transfermay be different.
- supported ( CMD )
- Returns TRUE if the remote server supports the given command.
The following methods can return different results depending onhow they are called. If the user explicitly calls eitherof the pasv or port methods then these methods willreturn a true or false value. If the user does notcall either of these methods then the result will be areference to a Net::FTP::dataconn based object.
- nlst ( [ DIR ] )
- Send a NLST command to the server, with an optional parameter.
- list ( [ DIR ] )
- Same as nlst but using the LIST command
- retr ( FILE )
- Begin the retrieval of a file called FILE from the remote server.
- stor ( FILE )
- Tell the server that you wish to store a file. FILE is thename of the new file that should be created.
- stou ( FILE )
- Same as stor but using the STOU command. The name of the uniquefile which was created on the server will be available via the unique_namemethod after the data connection has been closed.
- appe ( FILE )
- Tell the server that we want to append some data to the end of a filecalled FILE. If this file does not exist then create it.
If for some reason you want to have complete control over the data connection,this includes generating it and calling the response method when required,then the user can use these methods to do so.
However calling these methods only affects the use of the methods above thatcan return a data connection. They have no effect on methods get, put,put_unique and those that do not require data connections.
- port ( [ PORT ] )
- Send a PORT command to the server. If PORT is specified then it is sentto the server. If not the a listen socket is created and the correct informationsent to the server.
- pasv ()
- Tell the server to go into passive mode. Returns the text that represents theport on which the server is listening, this text is in a suitable form tosent to another ftp server using the port method.
The following methods can be used to transfer files between two remoteservers, providing that these two servers can connect directly to each other.
- pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
- This method will do a file transfer between two remote ftp servers. IfDEST_FILE is omitted then the leaf name of SRC_FILE will be used.
- pasv_xfer_unique ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
- Like pasv_xfer but the file is stored on the remote server usingthe STOU command.
- pasv_wait ( NON_PASV_SERVER )
- This method can be used to wait for a transfer to complete between a passiveserver and a non-passive server. The method should be called on the passiveserver with the Net::FTP object for the non-passive server passed as anargument.
- abort ()
- Abort the current data transfer.
- quit ()
- Send the QUIT command to the remote FTP server and close the socket connection.
Methods for the adventurous
Net::FTP inherits from
Net::Cmd so methods defined in
Net::Cmd maybe used to send commands to the remote
FTP server.
- quot (CMD [,ARGS])
- Send a command, that Net::FTP does not directly support, to the remoteserver and wait for a response.
Returns most significant digit of the response code.
WARNING This call should only be used on commands that do not requiredata connections. Misuse of this method can hang the connection.
THE dataconn CLASS
Some of the methods defined in
Net::FTP return an object which willbe derived from this class.The dataconn class itself is derived fromthe
IO::Socket::INET class, so any normal IO operations can be performed.However the following methods are defined in the dataconn class and IO shouldbe performed using these.
- read ( BUFFER, SIZE [, TIMEOUT ] )
- Read SIZE bytes of data from the server and place it into BUFFER, alsoperforming any <CRLF> translation necessary. TIMEOUT is optional, if notgiven the the timeout value from the command connection will be used.
Returns the number of bytes read before any <CRLF> translation.
- write ( BUFFER, SIZE [, TIMEOUT ] )
- Write SIZE bytes of data from BUFFER to the server, alsoperforming any <CRLF> translation necessary. TIMEOUT is optional, if notgiven the the timeout value from the command connection will be used.
Returns the number of bytes written before any <CRLF> translation.
- abort ()
- Abort the current data transfer.
- close ()
- Close the data connection and get a response from the FTP server. Returnstrue if the connection was closed successfully and the first digit ofthe response from the server was a `2'.
UNIMPLEMENTED
The following RFC959 commands have not been implemented:
- ALLO
- Allocates storage for the file to be transferred.
- SMNT
- Mount a different file system structure without changing login oraccounting information.
- HELP
- Ask the server for ``helpful information'' (that's what the RFC says) onthe commands it accepts.
- MODE
- Specifies transfer mode (stream, block or compressed) for file to betransferred.
- SYST
- Request remote server system identification.
- STAT
- Request remote server status.
- STRU
- Specifies file structure for file to be transferred.
- REIN
- Reinitialize the connection, flushing all I/O and account information.
REPORTING BUGS
When reporting bugs/problems please include as much information as possible.It may be difficult for me to reproduce the problem as almost every setupis different.
A small script which yields the problem will probably be of help. It wouldalso be useful if this script was run with the extra options Debug = 1>passed to the constructor, and the output sent with the bug report. If youcannot include a small script then please include a Debug trace from arun of your program which does yield the problem.
AUTHOR
Graham Barr <gbarrAATTpobox.com>
SEE ALSO
the
Net::Netrc manpagethe
Net::Cmd manpage
ftp(1), ftpd(8), RFC 959http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html
CREDITS
Henry Gabryjelski <henrygAATTWPI.EDU> - for the suggestion of creating directoriesrecursively.
Nathan Torkington <gnatAATTfrii.com> - for some input on the documentation.
Roderick Schertler <roderickAATTgate.net> - for various inputs
COPYRIGHT
Copyright (c) 1995-1998 Graham Barr. All rights reserved.This program is free software; you can redistribute it and/or modify itunder the same terms as Perl itself.
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- OVERVIEW
- CONSTRUCTOR
- METHODS
- Methods for the adventurous
- THE dataconn CLASS
- UNIMPLEMENTED
- REPORTING BUGS
- AUTHOR
- SEE ALSO
- CREDITS
- COPYRIGHT
This document was created byman2html,using the manual pages.