<pre name="code" class="sql">Net::FTP(3) User Contributed Perl Documentation Net::FTP(3)
NAME
Net::FTP - FTP Client class
SYNOPSIS
use Net::FTP;
$ftp = Net::FTP->new("some.host.name", Debug => 0)
or die "Cannot connect to some.host.name: $@"; ---创建对象
$ftp->login("anonymous",'-anonymous@') ---调用对象的login方法
or die "Cannot login ", $ftp->message;
$ftp->cwd("/pub") --调用对象的cmd方法
or die "Cannot change working directory ", $ftp->message;
$ftp->get("that.file")
or die "get failed ", $ftp->message;
$ftp->quit;
DESCRIPTION
"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.
Net::FTP 是一个类 实现一个简单的FTP客户端在Perl里
OVERVIEW
FTP stands for File Transfer Protocol. It is a way of transferring files between networked machines. The protocol defines a client (whose commands are provided by this
module) and a server (not implemented in this module). Communication is always initiated by the client, and the server responds with a message and a status code (and
sometimes with data).
概要:
FTP 掉膘文件传输协议。它是一种传输文件的方式在网络机器间,
协议定义了一个客户端( 有这个模块提供命令) 和服务器( 不包括在这个模块)。
通信总是有客户端发起,服务器响应一个消息或者一个状态码(或者一些数据)
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.
FTP 协议允许文件被发送或者从服务器上获取。每次传送调用一个本地的文件(在客户端上)和一个远程的文件(在服务器上). 在这个模块里,
同样的文件会被用于本地和远程,如果只有一个被指定。
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).
该协议定义了几个标准的传输,该文件可以在传输过程中进行.这里有ASCII,EBDCIC,binary,和bytes 模式。ASCII 是默认的模式。
CONSTRUCTOR
new ([ HOST ] [, OPTIONS ])
This is the constructor for a new Net::FTP object. "HOST" is the name of the remote host to which an FTP connection is required.
"HOST" is optional. If "HOST" is not given then it may instead be passed as the "Host" option described below.
"OPTIONS" are passed in a hash like fashion, using key and value pairs. Possible options are:
Host - FTP host to connect to. It may be a single scalar, as defined for the "PeerAddr" option in IO::Socket::INET, or a reference to an array with hosts to try in turn.
The "host" method will return the value which was used to connect to the host.
Firewall - The name of a machine which acts as an 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
referred to as an ftp proxy.
FirewallType - The type of firewall running on the machine indicated by Firewall. This can be overridden by an environment variable "FTP_FIREWALL_TYPE". For a list of
permissible types, see the description of ftp_firewall_type in Net::Config.
BlockSize - This is the block size that Net::FTP will use when doing transfers. (defaults to 10240)
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 Net::Cmd)
Passive - If set to a non-zero value then all data transfers will be done using passive mode. If set to zero then data transfers will be done using active mode. If the
machine is connected to the Internet directly, both passive and active mode should work equally well. Behind most firewall and NAT configurations passive mode has a
better chance of working. However, in some rare firewall configurations, active mode actually works when passive mode doesn’t. Some really old FTP servers might not
implement passive transfers. If not specified, then the transfer mode is set by the environment variable "FTP_PASSIVE" or if that one is not set by the settings done by
the libnetcfg utility. If none of these apply then passive mode is used.
Hash - If given a reference to a file handle (e.g., "*STDERR"), print hash marks (#) on that filehandle every 1024 bytes. This simply invokes the "hash()" method for
you, so that hash marks are displayed for all transfers. You can, of course, call "hash()" explicitly whenever you’d like.
LocalAddr - Local address to use for all socket connections, this argument will be passed to IO::Socket::INET
If the constructor fails undef will be returned and an error message will be in $@
构造函数:new ([ HOST ] [, OPTIONS ])
这是构造一个新的 Net::FTP对相,"HOST"是远程FTP主机,是FTP连接的需要。
主机是可选项,如果"HOST" 没有指定,可能代替传入作为"Host"选项 下面有描述
选项是一种hash方式传入,即使用键值对。可能的选择是:
METHODS 方法:
Unless otherwise stated all methods return either a true or false value, with true meaning that the operation was a success. When a method states that it returns a value,
failure will be returned as undef or an empty list.
除非另有说明, 所有的方式返回真或者假值,真表示操作是成功的。当一个方法返回一个值, failure 会返回undef 或者空的列表
login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])
Log into the remote FTP server with the given login information. If no arguments are given then the "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 anonymous@ will
be used for password.
If the connection is via a firewall then the "authorize" method will be called with no arguments.