📄 ftp-objects.html
字号:
<P>
<dl><dt><b><a name='l2h-2052'><tt class='method'>storlines</tt></a></b> (<var>command, file</var>)
<dd>
Store a file in ASCII transfer mode. <var>command</var> should be an
appropriate "<tt class="samp">STOR</tt>" command (see <tt class="method">storbinary()</tt>). Lines are
read until EOF from the open file object <var>file</var> using its
<tt class="method">readline()</tt> method to provide the data to be stored.
</dl>
<P>
<dl><dt><b><a name='l2h-2053'><tt class='method'>transfercmd</tt></a></b> (<var>cmd</var><big>[</big><var>, rest</var><big>]</big>)
<dd>
Initiate a transfer over the data connection. If the transfer is
active, send a "<tt class="samp">PORT</tt>" command and the transfer command specified
by <var>cmd</var>, and accept the connection. If the server is passive,
send a "<tt class="samp">PASV</tt>" command, connect to it, and start the transfer
command. Either way, return the socket for the connection.
<P>
If optional <var>rest</var> is given, a "<tt class="samp">REST</tt>" command is
sent to the server, passing <var>rest</var> as an argument. <var>rest</var> is
usually a byte offset into the requested file, telling the server to
restart sending the file's bytes at the requested offset, skipping
over the initial bytes. Note however that RFC
959 requires only that <var>rest</var> be a string containing characters
in the printable range from ASCII code 33 to ASCII code 126. The
<tt class="method">transfercmd()</tt> method, therefore, converts
<var>rest</var> to a string, but no check is
performed on the string's contents. If the server does
not recognize the "<tt class="samp">REST</tt>" command, an
<tt class="exception">error_reply</tt> exception will be raised. If this happens,
simply call <tt class="method">transfercmd()</tt> without a <var>rest</var> argument.
</dl>
<P>
<dl><dt><b><a name='l2h-2054'><tt class='method'>ntransfercmd</tt></a></b> (<var>cmd</var><big>[</big><var>, rest</var><big>]</big>)
<dd>
Like <tt class="method">transfercmd()</tt>, but returns a tuple of the data
connection and the expected size of the data. If the expected size
could not be computed, <code>None</code> will be returned as the expected
size. <var>cmd</var> and <var>rest</var> means the same thing as in
<tt class="method">transfercmd()</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-2055'><tt class='method'>nlst</tt></a></b> (<var>argument</var><big>[</big><var>, ...</var><big>]</big>)
<dd>
Return a list of files as returned by the "<tt class="samp">NLST</tt>" command. The
optional <var>argument</var> is a directory to list (default is the current
server directory). Multiple arguments can be used to pass
non-standard options to the "<tt class="samp">NLST</tt>" command.
</dl>
<P>
<dl><dt><b><a name='l2h-2056'><tt class='method'>dir</tt></a></b> (<var>argument</var><big>[</big><var>, ...</var><big>]</big>)
<dd>
Produce a directory listing as returned by the "<tt class="samp">LIST</tt>" command,
printing it to standard output. The optional <var>argument</var> is a
directory to list (default is the current server directory). Multiple
arguments can be used to pass non-standard options to the "<tt class="samp">LIST</tt>"command. If the last argument is a function, it is used as a
<var>callback</var> function as for <tt class="method">retrlines()</tt>; the default
prints to <code>sys.stdout</code>. This method returns <code>None</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-2057'><tt class='method'>rename</tt></a></b> (<var>fromname, toname</var>)
<dd>
Rename file <var>fromname</var> on the server to <var>toname</var>.
</dl>
<P>
<dl><dt><b><a name='l2h-2058'><tt class='method'>delete</tt></a></b> (<var>filename</var>)
<dd>
Remove the file named <var>filename</var> from the server. If successful,
returns the text of the response, otherwise raises
<tt class="exception">error_perm</tt> on permission errors or
<tt class="exception">error_reply</tt> on other errors.
</dl>
<P>
<dl><dt><b><a name='l2h-2059'><tt class='method'>cwd</tt></a></b> (<var>pathname</var>)
<dd>
Set the current directory on the server.
</dl>
<P>
<dl><dt><b><a name='l2h-2060'><tt class='method'>mkd</tt></a></b> (<var>pathname</var>)
<dd>
Create a new directory on the server.
</dl>
<P>
<dl><dt><b><a name='l2h-2061'><tt class='method'>pwd</tt></a></b> ()
<dd>
Return the pathname of the current directory on the server.
</dl>
<P>
<dl><dt><b><a name='l2h-2062'><tt class='method'>rmd</tt></a></b> (<var>dirname</var>)
<dd>
Remove the directory named <var>dirname</var> on the server.
</dl>
<P>
<dl><dt><b><a name='l2h-2063'><tt class='method'>size</tt></a></b> (<var>filename</var>)
<dd>
Request the size of the file named <var>filename</var> on the server. On
success, the size of the file is returned as an integer, otherwise
<code>None</code> is returned. Note that the "<tt class="samp">SIZE</tt>" command is not
standardized, but is supported by many common server implementations.
</dl>
<P>
<dl><dt><b><a name='l2h-2064'><tt class='method'>quit</tt></a></b> ()
<dd>
Send a "<tt class="samp">QUIT</tt>" command to the server and close the connection.
This is the ``polite'' way to close a connection, but it may raise an
exception of the server reponds with an error to the
"<tt class="samp">QUIT</tt>" command. This implies a call to the <tt class="method">close()</tt>
method which renders the <tt class="class">FTP</tt> instance useless for subsequent
calls (see below).
</dl>
<P>
<dl><dt><b><a name='l2h-2065'><tt class='method'>close</tt></a></b> ()
<dd>
Close the connection unilaterally. This should not be applied to an
already closed connection (e.g. after a successful call to
<tt class="method">quit()</tt>. After this call the <tt class="class">FTP</tt> instance should not
be used any more (i.e., after a call to <tt class="method">close()</tt> or
<tt class="method">quit()</tt> you cannot reopen the connection by issuing another
<tt class="method">login()</tt> method).
</dl>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-ftplib.html" tppabs="http://www.python.org/doc/current/lib/module-ftplib.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="module-ftplib.html" tppabs="http://www.python.org/doc/current/lib/module-ftplib.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-gopherlib.html" tppabs="http://www.python.org/doc/current/lib/module-gopherlib.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-ftplib.html" tppabs="http://www.python.org/doc/current/lib/module-ftplib.html">11.5 ftplib </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-ftplib.html" tppabs="http://www.python.org/doc/current/lib/module-ftplib.html">11.5 ftplib </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-gopherlib.html" tppabs="http://www.python.org/doc/current/lib/module-gopherlib.html">11.6 gopherlib </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -