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

📄 module-ftplib.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.5 ftplib -- FTP protocol client</title>
<META NAME="description" CONTENT="11.5 ftplib -- FTP protocol client">
<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="next" href="module-gopherlib.html" tppabs="http://www.python.org/doc/current/lib/module-gopherlib.html">
<LINK REL="previous" href="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.html">
<LINK REL="up" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">
<LINK REL="next" href="ftp-objects.html" tppabs="http://www.python.org/doc/current/lib/ftp-objects.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.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="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.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="ftp-objects.html" tppabs="http://www.python.org/doc/current/lib/ftp-objects.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="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.html">11.4.2 Examples</A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" href="ftp-objects.html" tppabs="http://www.python.org/doc/current/lib/ftp-objects.html">11.5.1 FTP Objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION0013500000000000000000">
11.5 <tt class="module">ftplib</tt> --
         FTP protocol client</A>
</H1>

<P>


<P>
This module defines the class <tt class="class">FTP</tt> and a few related items.
The <tt class="class">FTP</tt> class implements the client side of the FTP
protocol.  You can use this to write Python
programs that perform a variety of automated FTP jobs, such as
mirroring other ftp servers.  It is also used by the module
<tt class='module'><a href="module-urllib.html" tppabs="http://www.python.org/doc/current/lib/module-urllib.html">urllib</a></tt> to handle URLs that use FTP.  For more information
on FTP (File Transfer Protocol), see Internet <a class="rfc" name="rfcref-46994"
href="javascript:if(confirm('http://www.ietf.org/rfc/rfc0959.txt  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc0959.txt'" tppabs="http://www.ietf.org/rfc/rfc0959.txt">RFC 959 <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
  border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
  ></a>.

<P>
Here's a sample session using the <tt class="module">ftplib</tt> module:

<P>
<dl><dd><pre class="verbatim">
&gt;&gt;&gt; from ftplib import FTP
&gt;&gt;&gt; ftp = FTP('ftp.cwi.nl')   # connect to host, default port
&gt;&gt;&gt; ftp.login()               # user anonymous, passwd user@hostname
&gt;&gt;&gt; ftp.retrlines('LIST')     # list directory contents
total 24418
drwxrwsr-x   5 ftp-usr  pdmaint     1536 Mar 20 09:48 .
dr-xr-srwt 105 ftp-usr  pdmaint     1536 Mar 21 14:32 ..
-rw-r--r--   1 ftp-usr  pdmaint     5305 Mar 20 09:48 INDEX
 .
 .
 .
&gt;&gt;&gt; ftp.retrbinary('RETR README', open('README', 'wb').write)
'226 Transfer complete.'
&gt;&gt;&gt; ftp.quit()
</pre></dl>

<P>
The module defines the following items:

<P>
<dl><dt><b><a name='l2h-2033'><tt class='class'>FTP</tt></a></b> (<big>[</big><var>host</var><big>[</big><var>, user</var><big>[</big><var>,
                       passwd</var><big>[</big><var>, acct</var><big>]</big><big>]</big><big>]</big><big>]</big>)
<dd>
Return a new instance of the <tt class="class">FTP</tt> class.  When
<var>host</var> is given, the method call <code>connect(<var>host</var>)</code> is
made.  When <var>user</var> is given, additionally the method call
<code>login(<var>user</var>, <var>passwd</var>, <var>acct</var>)</code> is made (where
<var>passwd</var> and <var>acct</var> default to the empty string when not given).
</dl>

<P>
<dl><dt><b><a name='l2h-2034'><tt>all_errors</tt></a></b>
<dd>
The set of all exceptions (as a tuple) that methods of <tt class="class">FTP</tt>
instances may raise as a result of problems with the FTP connection
(as opposed to programming errors made by the caller).  This set
includes the four exceptions listed below as well as
<tt class="exception">socket.error</tt> and <tt class="exception">IOError</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-2035'><tt class='exception'>error_reply</tt></a></b>
<dd>
Exception raised when an unexpected reply is received from the server.
</dl>

<P>
<dl><dt><b><a name='l2h-2036'><tt class='exception'>error_temp</tt></a></b>
<dd>
Exception raised when an error code in the range 400-499 is received.
</dl>

<P>
<dl><dt><b><a name='l2h-2037'><tt class='exception'>error_perm</tt></a></b>
<dd>
Exception raised when an error code in the range 500-599 is received.
</dl>

<P>
<dl><dt><b><a name='l2h-2038'><tt class='exception'>error_proto</tt></a></b>
<dd>
Exception raised when a reply is received from the server that does
not begin with a digit in the range 1-5.
</dl>

<P>
<div class='seealso'>
  <p class='heading'><b>See Also:</b></p>

  <dl compact class="seemodule">
    <dt>Module <b><tt class='module'><a href="module-netrc.html" tppabs="http://www.python.org/doc/current/lib/module-netrc.html">netrc</a></tt>:</b>
    <dd>Parser for the <span class="file">.netrc</span> file format.  The file
                    <span class="file">.netrc</span> is typically used by FTP clients to
                    load user authentication information before prompting
                    the user.
  </dl>
  <div class="seetext"><p>The file <span class="file">Tools/scripts/ftpmirror.py</span>
           in the Python source distribution is a script that can mirror
           FTP sites, or portions thereof, using the <tt class="module">ftplib</tt> module.
           It can be used as an extended example that applies this module.</div>
</div>

<P>

<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>

<UL>
<LI><A NAME="tex2html3980"
  href="ftp-objects.html" tppabs="http://www.python.org/doc/current/lib/ftp-objects.html">11.5.1 FTP Objects </A>
</UL>
<!--End of Table of Child-Links-->

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.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="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.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="ftp-objects.html" tppabs="http://www.python.org/doc/current/lib/ftp-objects.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="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.html">11.4.2 Examples</A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" href="ftp-objects.html" tppabs="http://www.python.org/doc/current/lib/ftp-objects.html">11.5.1 FTP Objects</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 + -