ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH
advanced | search help

Reference
ActivePython 2.4
Python Documentation
Library Reference
11. Internet Protocols and Support
11.1 webbrowser -- Convenient Web-browser controller
11.2 cgi -- Common Gateway Interface support.
11.3 cgitb -- Traceback manager for CGI scripts
11.4 urllib -- Open arbitrary resources by URL
11.5 urllib2 -- extensible library for opening URLs
11.6 httplib -- HTTP protocol client
11.7 ftplib -- FTP protocol client
11.7.1 FTP Objects
11.8 gopherlib -- Gopher protocol client
11.9 poplib -- POP3 protocol client
11.10 imaplib -- IMAP4 protocol client
11.11 nntplib -- NNTP protocol client
11.12 smtplib -- SMTP protocol client
11.13 smtpd -- SMTP Server
11.14 telnetlib -- Telnet client
11.15 urlparse -- Parse URLs into components
11.16 SocketServer -- A framework for network servers
11.17 BaseHTTPServer -- Basic HTTP server
11.18 SimpleHTTPServer -- Simple HTTP request handler
11.19 CGIHTTPServer -- CGI-capable HTTP request handler
11.20 cookielib -- Cookie handling for HTTP clients
11.21 Cookie -- HTTP state management
11.22 xmlrpclib -- XML-RPC client access
11.23 SimpleXMLRPCServer -- Basic XML-RPC server
11.24 DocXMLRPCServer -- Self-documenting XML-RPC server
11.25 asyncore -- Asynchronous socket handler
11.26 asynchat -- Asynchronous socket command/response handler

MyASPN >> Reference >> ActivePython 2.4 >> Python Documentation >> Library Reference >> 11. Internet Protocols and Support
ActivePython 2.4 documentation

11.7 ftplib -- FTP protocol client

This module defines the class FTP and a few related items. The FTP 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 urllib to handle URLs that use FTP. For more information on FTP (File Transfer Protocol), see Internet RFC 959.

Here's a sample session using the ftplib module:

>>> from ftplib import FTP
>>> ftp = FTP('ftp.cwi.nl')   # connect to host, default port
>>> ftp.login()               # user anonymous, passwd anonymous@
>>> 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
 .
 .
 .
>>> ftp.retrbinary('RETR README', open('README', 'wb').write)
'226 Transfer complete.'
>>> ftp.quit()

The module defines the following items:

class FTP( [host[, user[, passwd[, acct]]]])
Return a new instance of the FTP class. When host is given, the method call connect(host) is made. When user is given, additionally the method call login(user, passwd, acct) is made (where passwd and acct default to the empty string when not given).

all_errors
The set of all exceptions (as a tuple) that methods of FTP 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 socket.error and IOError.

exception error_reply
Exception raised when an unexpected reply is received from the server.

exception error_temp
Exception raised when an error code in the range 400-499 is received.

exception error_perm
Exception raised when an error code in the range 500-599 is received.

exception error_proto
Exception raised when a reply is received from the server that does not begin with a digit in the range 1-5.

See Also:

Module netrc:
Parser for the .netrc file format. The file .netrc is typically used by FTP clients to load user authentication information before prompting the user.

The file Tools/scripts/ftpmirror.py in the Python source distribution is a script that can mirror FTP sites, or portions thereof, using the ftplib module. It can be used as an extended example that applies this module.



See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved