⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftp-objects.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.5.1 FTP Objects </title>
<META NAME="description" CONTENT="11.5.1 FTP Objects ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="previous" href="module-ftplib.html" tppabs="http://www.python.org/doc/current/lib/module-ftplib.html">
<LINK REL="up" href="module-ftplib.html" tppabs="http://www.python.org/doc/current/lib/module-ftplib.html">
<LINK REL="next" href="module-gopherlib.html" tppabs="http://www.python.org/doc/current/lib/module-gopherlib.html">
</head>
<body>
<DIV CLASS="navigation"><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>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H2>
<BR>
11.5.1 FTP Objects 
</H2>

<P>
Several methods are available in two flavors: one for handling text
files and another for binary files.  These are named for the command
which is used followed by "<tt class="samp">lines</tt>" for the text version or
"<tt class="samp">binary</tt>" for the binary version.

<P>
<tt class="class">FTP</tt> instances have the following methods:

<P>
<dl><dt><b><a name='l2h-2041'><tt class='method'>set_debuglevel</tt></a></b> (<var>level</var>)
<dd>
Set the instance's debugging level.  This controls the amount of
debugging output printed.  The default, <code>0</code>, produces no
debugging output.  A value of <code>1</code> produces a moderate amount of
debugging output, generally a single line per request.  A value of
<code>2</code> or higher produces the maximum amount of debugging output,
logging each line sent and received on the control connection.
</dl>

<P>
<dl><dt><b><a name='l2h-2042'><tt class='method'>connect</tt></a></b> (<var>host</var><big>[</big><var>, port</var><big>]</big>)
<dd>
Connect to the given host and port.  The default port number is <code>21</code>, as
specified by the FTP protocol specification.  It is rarely needed to
specify a different port number.  This function should be called only
once for each instance; it should not be called at all if a host was
given when the instance was created.  All other methods can only be
used after a connection has been made.
</dl>

<P>
<dl><dt><b><a name='l2h-2043'><tt class='method'>getwelcome</tt></a></b> ()
<dd>
Return the welcome message sent by the server in reply to the initial
connection.  (This message sometimes contains disclaimers or help
information that may be relevant to the user.)
</dl>

<P>
<dl><dt><b><a name='l2h-2044'><tt class='method'>login</tt></a></b> (<big>[</big><var>user</var><big>[</big><var>, passwd</var><big>[</big><var>, acct</var><big>]</big><big>]</big><big>]</big>)
<dd>
Log in as the given <var>user</var>.  The <var>passwd</var> and <var>acct</var>
parameters are optional and default to the empty string.  If no
<var>user</var> is specified, it defaults to <code>'anonymous'</code>.  If
<var>user</var> is <code>'anonymous'</code>, the default <var>passwd</var> is
"<tt class="samp"><var>realuser</var>@<var>host</var></tt>" where <var>realuser</var> is the real user
name (glanced from the <a class="envvar" name='l2h-2066'>$LOGNAME</a> or <a class="envvar" name='l2h-2067'>$USER</a> environment
variable) and <var>host</var> is the hostname as returned by
<tt class="function">socket.gethostname()</tt>.  This function should be called only
once for each instance, after a connection has been established; it
should not be called at all if a host and user were given when the
instance was created.  Most FTP commands are only allowed after the
client has logged in.
</dl>

<P>
<dl><dt><b><a name='l2h-2045'><tt class='method'>abort</tt></a></b> ()
<dd>
Abort a file transfer that is in progress.  Using this does not always
work, but it's worth a try.
</dl>

<P>
<dl><dt><b><a name='l2h-2046'><tt class='method'>sendcmd</tt></a></b> (<var>command</var>)
<dd>
Send a simple command string to the server and return the response
string.
</dl>

<P>
<dl><dt><b><a name='l2h-2047'><tt class='method'>voidcmd</tt></a></b> (<var>command</var>)
<dd>
Send a simple command string to the server and handle the response.
Return nothing if a response code in the range 200-299 is received.
Raise an exception otherwise.
</dl>

<P>
<dl><dt><b><a name='l2h-2048'><tt class='method'>retrbinary</tt></a></b> (<var>command,
    callback</var><big>[</big><var>, maxblocksize</var><big>[</big><var>, rest</var><big>]</big><big>]</big>)
<dd>
Retrieve a file in binary transfer mode.  <var>command</var> should be an
appropriate "<tt class="samp">RETR</tt>" command, i.e. <code>'RETR <var>filename</var>'</code>.
The <var>callback</var> function is called for each block of data received,
with a single string argument giving the data block.
The optional <var>maxblocksize</var> argument specifies the maximum chunk size to
read on the low-level socket object created to do the actual transfer
(which will also be the largest size of the data blocks passed to
<var>callback</var>).  A reasonable default is chosen. <var>rest</var> means the
same thing as in the <tt class="method">transfercmd()</tt> method.
</dl>

<P>
<dl><dt><b><a name='l2h-2049'><tt class='method'>retrlines</tt></a></b> (<var>command</var><big>[</big><var>, callback</var><big>]</big>)
<dd>
Retrieve a file or directory listing in ASCII transfer mode.
<var>command</var> should be an appropriate "<tt class="samp">RETR</tt>" command (see
<tt class="method">retrbinary()</tt> or a "<tt class="samp">LIST</tt>" command (usually just the string
<code>'LIST'</code>).  The <var>callback</var> function is called for each line,
with the trailing CRLF stripped.  The default <var>callback</var> prints
the line to <code>sys.stdout</code>.
</dl>

<P>
<dl><dt><b><a name='l2h-2050'><tt class='method'>set_pasv</tt></a></b> (<var>boolean</var>)
<dd>
Enable ``passive'' mode if <var>boolean</var> is true, other disable
passive mode.
</dl>

<P>
<dl><dt><b><a name='l2h-2051'><tt class='method'>storbinary</tt></a></b> (<var>command, file, blocksize</var>)
<dd>
Store a file in binary transfer mode.  <var>command</var> should be an
appropriate "<tt class="samp">STOR</tt>" command, i.e. <code>"STOR <var>filename</var>"</code>.
<var>file</var> is an open file object which is read until EOF using its
<tt class="method">read()</tt> method in blocks of size <var>blocksize</var> to provide the
data to be stored.
</dl>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -