![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
use Net::FTP; $ftp = Net::FTP->new("some.host.name"); $ftp->login("anonymous","me@here.there"); $ftp->cwd("/pub"); $ftp->get("that.file"); $ftp->quit;
Net::FTP
is a class implementing a simple FTP client in Perl as described in RFC959.
It provides wrappers for a subset of the RFC959 commands.
The FTP protocol allows files to be sent to or fetched from the server.
Each transfer involves a local file (on the client) and a
remote file (on the server). In this module, the same file name will be used for both
local and remote if only one is specified. This means that transferring
remote file /path/to/file
will try to put that file in /path/to/file
locally, unless you specify a local file name.
The protocol also defines several standard translations which the file can undergo during transfer. These are ASCII, EBCDIC, binary, and byte. ASCII is the default type, and indicates that the sender of files will translate the ends of lines to a standard representation which the receiver will then translate back into their local representation. EBCDIC indicates the file being transferred is in EBCDIC format. Binary (also known as image) format sends the data as a contiguous bit stream. Byte format transfers the data as bytes, the values of which remain the same regardless of differences in byte size between the two machines (in theory - in practice you should only use this if you really know what you're doing).
HOST
is the name 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 be
overridden by an environment variable FTP_FIREWALL
. If specified, and the given host cannot be directly connected to, then
the connection is made to the firewall machine and the string @hostname
is appended to the login identifier. This kind of setup is also refered to
as a ftp proxy.
Port - The port number to connect to on the remote machine for the FTP connection
Timeout - Set a timeout value (defaults to 120)
Debug - debug level (see the debug method in Cmd)
Passive - If set to true then all data transfers will be done using passive mode. This is required
for some dumb servers, and some firewall configurations. This can also be set by the
environment variable FTP_PASSIVE
.
Net::FTP
uses the Net::Netrc
package 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 users Email address will be used for a password.
If the connection is via a firewall then the authorize method will be called with no arguments.
Net::Netrc
to do a lookup.
NOTE ebcdic and byte are not fully supported.
OLDNAME
to NEWNAME
. This is done by sending the RNFR and RNTO commands.
FILENAME
.
".."
, the FTP CDUP
command is used to attempt to move up one directory. If no directory is
given then an attempt is made to change the directory to the root
directory.
DIR
.
DIR
. If RECURSE
is true then
mkdir will attempt to create all the directories in the given path.
Returns the full pathname to the new directory.
DIR
, or the current directory.
Returns a reference to a list of lines returned from the server.
DIR
, or the current directory in long format.
Returns a reference to a list of lines returned from the server.
REMOTE_FILE
from the server and store locally. LOCAL_FILE
may be a filename or a filehandle. If not specified the the file will be
stored in the current directory with the same leafname as the remote file.
If WHERE
is specified, continue transfer of the remote file from this point.
Returns LOCAL_FILE
, or the generated local file name if LOCAL_FILE
is not given.
LOCAL_FILE
may be a name or a filehandle. If LOCAL_FILE
is a filehandle then REMOTE_FILE
must be specified. If
REMOTE_FILE
is not specified then the file will be stored in the current directory with
the same leafname as LOCAL_FILE
.
Returns REMOTE_FILE
, or the generated remote filename if REMOTE_FILE
is not given.
STOU
command.
Returns the name of the file on the server.
Returns REMOTE_FILE
, or the generated remote filename if REMOTE_FILE
is not given.
STOU
command.
Net::FTP::dataconn
based object.
NLST
command to the server, with an optional parameter.
LIST
command
FILE
from the remote server.
FILE
is the name of the new file that should be created.
STOU
command. The name of the unique file which was created on the server will
be available via the unique_name
method after the data connection has been closed.
FILE
. If this file does not exist then create it.
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 that can return a data connection. They have no effect on methods get, put, put_unique and those that do not require data connections.
PORT
command to the server. If PORT
is specified then it is sent to the server. If not the a listen socket is
created and the correct information sent to the server.
DEST_FILE
is omitted then the leaf name of SRC_FILE
will be used.
Net::FTP
object for the non-passive server passed as an argument.
Net::FTP
inherits from Net::Cmd
so methods defined in Net::Cmd
may be used to send commands to the remote FTP server.
Returns most significant digit of the response code.
WARNING This call should only be used on commands that do not require data connections. Misuse of this method can hang the connection.
Net::FTP
return an object which will be derived from this class.The dataconn class
itself is derived from the IO::Socket::INET
class, so any normal IO operations can be performed. However the following
methods are defined in the dataconn class and IO should be performed using
these.
SIZE
bytes of data from the server and place it into BUFFER
, also performing any <CRLF> translation necessary. TIMEOUT
is optional, if not given the the timeout value from the command connection
will be used.
Returns the number of bytes read before any <CRLF> translation.
SIZE
bytes of data from BUFFER
to the server, also performing any <CRLF> translation necessary. TIMEOUT
is optional, if not given the the timeout value from the command connection
will be used.
Returns the number of bytes written before any <CRLF> translation.
A small script which yields the problem will probably be of help. It would
also 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 you cannot include a small script then please include a Debug trace from
a run of your program which does yield the problem.
ftp(1),
ftpd(8),
RFC 959 http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html
Nathan Torkington
Roderick Schertler
$CommentsMailTo = "perl5@dcs.ed.ac.uk"; include("../syssies_footer.inc");?>