<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>11.4 ftplib --
FTP protocol client</TITLE>
<META NAME="description" CONTENT="11.4 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">
<LINK REL="next" HREF="module-gopherlib.html">
<LINK REL="previous" HREF="module-httplib.html">
<LINK REL="up" HREF="internet.html">
<LINK REL="next" HREF="ftp-objects.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="ftp-objects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="internet.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="HTTP_Example.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="ftp-objects.html">11.4.1 FTP Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="internet.html">11. Internet Protocols and</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="HTTP_Example.html">11.3.2 Example</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION0013400000000000000000">
11.4 <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.<a name="l2h-1645"></a>  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">urllib</a></tt> to handle URLs that use FTP.  For more information
on FTP (File Transfer Protocol), see Internet <span class=rfc><a name="rfcref-42314"
href="http://info.internet.isi.edu/in-notes/rfc/files/rfc959.txt">RFC 959</a></span>.

<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-1638"><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 <tt>connect(<var>host</var>)</tt> is
made.  When <var>user</var> is given, additionally the method call
<tt>login(<var>user</var>, <var>passwd</var>, <var>acct</var>)</tt> 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-1639"><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-1640"><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-1641"><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-1642"><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-1643"><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>

  <div class=seetext><p>The file <tt class=file>Tools/scripts/ftpmirror.py</tt><a name="l2h-1644"></a>
           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-->


<UL>
<LI><A NAME="tex2html3024"
 HREF="ftp-objects.html">11.4.1 FTP Objects </A>
</UL>
<!--End of Table of Child-Links-->
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="ftp-objects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="internet.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="HTTP_Example.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="ftp-objects.html">11.4.1 FTP Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="internet.html">11. Internet Protocols and</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="HTTP_Example.html">11.3.2 Example</A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
