ftp.html
来自「perl教程」· HTML 代码 · 共 745 行 · 第 1/2 页
HTML
745 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Net::FTP - FTP Client class</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>Net::FTP - FTP Client class</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#overview">OVERVIEW</a></li>
<li><a href="#constructor">CONSTRUCTOR</a></li>
<li><a href="#methods">METHODS</a></li>
<ul>
<li><a href="#methods_for_the_adventurous">Methods for the adventurous</a></li>
</ul>
<li><a href="#the_dataconn_class">THE dataconn CLASS</a></li>
<li><a href="#unimplemented">UNIMPLEMENTED</a></li>
<li><a href="#reporting_bugs">REPORTING BUGS</a></li>
<li><a href="#author">AUTHOR</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
<li><a href="#use_examples">USE EXAMPLES</a></li>
<li><a href="#credits">CREDITS</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Net::FTP - FTP Client class</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">Net::FTP</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$ftp</span> <span class="operator">=</span> <span class="variable">Net::FTP</span><span class="operator">-></span><span class="variable">new</span><span class="operator">(</span><span class="string">"some.host.name"</span><span class="operator">,</span> <span class="string">Debug</span> <span class="operator">=></span> <span class="number">0</span><span class="operator">)</span>
<span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Cannot connect to some.host.name: $@"</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$ftp</span><span class="operator">-></span><span class="variable">login</span><span class="operator">(</span><span class="string">"anonymous"</span><span class="operator">,</span><span class="string">'-anonymous@'</span><span class="operator">)</span>
<span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Cannot login "</span><span class="operator">,</span> <span class="variable">$ftp</span><span class="operator">-></span><span class="variable">message</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$ftp</span><span class="operator">-></span><span class="variable">cwd</span><span class="operator">(</span><span class="string">"/pub"</span><span class="operator">)</span>
<span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Cannot change working directory "</span><span class="operator">,</span> <span class="variable">$ftp</span><span class="operator">-></span><span class="variable">message</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$ftp</span><span class="operator">-></span><span class="variable">get</span><span class="operator">(</span><span class="string">"that.file"</span><span class="operator">)</span>
<span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"get failed "</span><span class="operator">,</span> <span class="variable">$ftp</span><span class="operator">-></span><span class="variable">message</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$ftp</span><span class="operator">-></span><span class="variable">quit</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p><code>Net::FTP</code> is a class implementing a simple FTP client in Perl as
described in RFC959. It provides wrappers for a subset of the RFC959
commands.</p>
<p>
</p>
<hr />
<h1><a name="overview">OVERVIEW</a></h1>
<p>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).</p>
<p>The FTP protocol allows files to be sent to or fetched from the
server. Each transfer involves a <strong>local file</strong> (on the client) and a
<strong>remote file</strong> (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 <code>/path/to/file</code> will try to put
that file in <code>/path/to/file</code> locally, unless you specify a local file
name.</p>
<p>The protocol also defines several standard <strong>translations</strong> 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).</p>
<p>
</p>
<hr />
<h1><a name="constructor">CONSTRUCTOR</a></h1>
<dl>
<dt><strong><a name="item_new">new ([ HOST ] [, OPTIONS ])</a></strong>
<dd>
<p>This is the constructor for a new Net::FTP object. <code>HOST</code> is the
name of the remote host to which an FTP connection is required.</p>
</dd>
<dd>
<p><code>HOST</code> is optional. If <code>HOST</code> is not given then it may instead be
passed as the <code>Host</code> option described below.</p>
</dd>
<dd>
<p><code>OPTIONS</code> are passed in a hash like fashion, using key and value pairs.
Possible options are:</p>
</dd>
<dd>
<p><strong>Host</strong> - FTP host to connect to. It may be a single scalar, as defined for
the <code>PeerAddr</code> option in <a href="../../lib/IO/Socket/INET.html">the IO::Socket::INET manpage</a>, or a reference to
an array with hosts to try in turn. The <a href="#host">host</a> method will return the value
which was used to connect to the host.</p>
</dd>
<dd>
<p><strong>Firewall</strong> - The name of a machine which acts as an FTP firewall. This can be
overridden by an environment variable <code>FTP_FIREWALL</code>. If specified, and the
given host cannot be directly connected to, then the
connection is made to the firewall machine and the string <code>@hostname</code> is
appended to the login identifier. This kind of setup is also refered to
as an ftp proxy.</p>
</dd>
<dd>
<p><strong>FirewallType</strong> - The type of firewall running on the machine indicated by
<strong>Firewall</strong>. This can be overridden by an environment variable
<code>FTP_FIREWALL_TYPE</code>. For a list of permissible types, see the description of
ftp_firewall_type in <a href="../../lib/Net/Config.html">the Net::Config manpage</a>.</p>
</dd>
<dd>
<p><strong>BlockSize</strong> - This is the block size that Net::FTP will use when doing
transfers. (defaults to 10240)</p>
</dd>
<dd>
<p><strong>Port</strong> - The port number to connect to on the remote machine for the
FTP connection</p>
</dd>
<dd>
<p><strong>Timeout</strong> - Set a timeout value (defaults to 120)</p>
</dd>
<dd>
<p><strong>Debug</strong> - debug level (see the debug method in <a href="../../lib/Net/Cmd.html">the Net::Cmd manpage</a>)</p>
</dd>
<dd>
<p><strong>Passive</strong> - 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
<code>FTP_PASSIVE</code> or if that one is not set by the settings done by the
<em>libnetcfg</em> utility. If none of these apply then passive mode is
used.</p>
</dd>
<dd>
<p><strong>Hash</strong> - If given a reference to a file handle (e.g., <code>\*STDERR</code>),
print hash marks (#) on that filehandle every 1024 bytes. This
simply invokes the <a href="#item_hash"><code>hash()</code></a> method for you, so that hash marks
are displayed for all transfers. You can, of course, call <a href="#item_hash"><code>hash()</code></a>
explicitly whenever you'd like.</p>
</dd>
<dd>
<p><strong>LocalAddr</strong> - Local address to use for all socket connections, this
argument will be passed to <a href="../../lib/IO/Socket/INET.html">the IO::Socket::INET manpage</a></p>
</dd>
<dd>
<p>If the constructor fails undef will be returned and an error message will
be in $@</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="methods">METHODS</a></h1>
<p>Unless otherwise stated all methods return either a <em>true</em> or <em>false</em>
value, with <em>true</em> meaning that the operation was a success. When a method
states that it returns a value, failure will be returned as <em>undef</em> or an
empty list.</p>
<dl>
<dt><strong><a name="item_login">login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])</a></strong>
<dd>
<p>Log into the remote FTP server with the given login information. If
no arguments are given then the <code>Net::FTP</code> uses the <code>Net::Netrc</code>
package to lookup the login information for the connected host.
If no information is found then a login of <em>anonymous</em> is used.
If no password is given and the login is <em>anonymous</em> then <em>anonymous@</em>
will be used for password.</p>
</dd>
<dd>
<p>If the connection is via a firewall then the <a href="#item_authorize"><code>authorize</code></a> method will
be called with no arguments.</p>
</dd>
</li>
<dt><strong><a name="item_authorize">authorize ( [AUTH [, RESP]])</a></strong>
<dd>
<p>This is a protocol used by some firewall ftp proxies. It is used
to authorise the user to send data out. If both arguments are not specified
then <a href="#item_authorize"><code>authorize</code></a> uses <code>Net::Netrc</code> to do a lookup.</p>
</dd>
</li>
<dt><strong><a name="item_site">site (ARGS)</a></strong>
<dd>
<p>Send a SITE command to the remote server and wait for a response.</p>
</dd>
<dd>
<p>Returns most significant digit of the response code.</p>
</dd>
</li>
<dt><strong><a name="item_ascii">ascii</a></strong>
<dd>
<p>Transfer file in ASCII. CRLF translation will be done if required</p>
</dd>
</li>
<dt><strong><a name="item_binary">binary</a></strong>
<dd>
<p>Transfer file in binary mode. No transformation will be done.</p>
</dd>
<dd>
<p><strong>Hint</strong>: If both server and client machines use the same line ending for
text files, then it will be faster to transfer all files in binary mode.</p>
</dd>
</li>
<dt><strong><a name="item_rename">rename ( OLDNAME, NEWNAME )</a></strong>
<dd>
<p>Rename a file on the remote FTP server from <code>OLDNAME</code> to <code>NEWNAME</code>. This
is done by sending the RNFR and RNTO commands.</p>
</dd>
</li>
<dt><strong><a name="item_delete">delete ( FILENAME )</a></strong>
<dd>
<p>Send a request to the server to delete <code>FILENAME</code>.</p>
</dd>
</li>
<dt><strong><a name="item_cwd">cwd ( [ DIR ] )</a></strong>
<dd>
<p>Attempt to change directory to the directory given in <code>$dir</code>. If
<code>$dir</code> is <code>".."</code>, the FTP <code>CDUP</code> 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.</p>
</dd>
</li>
<dt><strong><a name="item_cdup">cdup ()</a></strong>
<dd>
<p>Change directory to the parent of the current directory.</p>
</dd>
</li>
<dt><strong><a name="item_pwd">pwd ()</a></strong>
<dd>
<p>Returns the full pathname of the current directory.</p>
</dd>
</li>
<dt><strong><a name="item_restart">restart ( WHERE )</a></strong>
<dd>
<p>Set the byte offset at which to begin the next data transfer. Net::FTP simply
records this value and uses it when during the next data transfer. For this
reason this method will not return an error, but setting it may cause
a subsequent data transfer to fail.</p>
</dd>
</li>
<dt><strong><a name="item_rmdir">rmdir ( DIR [, RECURSE ])</a></strong>
<dd>
<p>Remove the directory with the name <code>DIR</code>. If <code>RECURSE</code> is <em>true</em> then
<a href="#item_rmdir"><code>rmdir</code></a> will attempt to delete everything inside the directory.</p>
</dd>
</li>
<dt><strong><a name="item_mkdir">mkdir ( DIR [, RECURSE ])</a></strong>
<dd>
<p>Create a new directory with the name <code>DIR</code>. If <code>RECURSE</code> is <em>true</em> then
<a href="#item_mkdir"><code>mkdir</code></a> will attempt to create all the directories in the given path.</p>
</dd>
<dd>
<p>Returns the full pathname to the new directory.</p>
</dd>
</li>
<dt><strong><a name="item_alloc">alloc ( SIZE [, RECORD_SIZE] )</a></strong>
<dd>
<p>The alloc command allows you to give the ftp server a hint about the size
of the file about to be transfered using the ALLO ftp command. Some storage
systems use this to make intelligent decisions about how to store the file.
The <code>SIZE</code> argument represents the size of the file in bytes. The
<code>RECORD_SIZE</code> argument indicates a mazimum record or page size for files
sent with a record or page structure.</p>
</dd>
<dd>
<p>The size of the file will be determined, and sent to the server
automatically for normal files so that this method need only be called if
you are transfering data from a socket, named pipe, or other stream not
associated with a normal file.</p>
</dd>
</li>
<dt><strong><a name="item_ls">ls ( [ DIR ] )</a></strong>
<dd>
<p>Get a directory listing of <code>DIR</code>, or the current directory.</p>
</dd>
<dd>
<p>In an array context, returns a list of lines returned from the server. In
a scalar context, returns a reference to a list.</p>
</dd>
</li>
<dt><strong><a name="item_dir">dir ( [ DIR ] )</a></strong>
<dd>
<p>Get a directory listing of <code>DIR</code>, or the current directory in long format.</p>
</dd>
<dd>
<p>In an array context, returns a list of lines returned from the server. In
a scalar context, returns a reference to a list.</p>
</dd>
</li>
<dt><strong><a name="item_get">get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )</a></strong>
<dd>
<p>Get <code>REMOTE_FILE</code> from the server and store locally. <code>LOCAL_FILE</code> may be
a filename or a filehandle. If not specified, the file will be stored in
the current directory with the same leafname as the remote file.</p>
</dd>
<dd>
<p>If <code>WHERE</code> is given then the first <code>WHERE</code> bytes of the file will
not be transfered, and the remaining bytes will be appended to
the local file if it already exists.</p>
</dd>
<dd>
<p>Returns <code>LOCAL_FILE</code>, or the generated local file name if <code>LOCAL_FILE</code>
is not given. If an error was encountered undef is returned.</p>
</dd>
</li>
<dt><strong><a name="item_put">put ( LOCAL_FILE [, REMOTE_FILE ] )</a></strong>
<dd>
<p>Put a file on the remote server. <code>LOCAL_FILE</code> may be a name or a filehandle.
If <code>LOCAL_FILE</code> is a filehandle then <code>REMOTE_FILE</code> must be specified. If
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?