Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:11.6.3 ExamplesUp:11. Internet Protocols andNext:11.7.1 FTP Objects

11.7ftplib -- FTP protocol client

 

This module defines the classFTP and a few related items.TheFTP class implements the client side of the FTPprotocol. You can use this to write Pythonprograms that perform a variety of automated FTP jobs, such asmirroring other ftp servers. It is also used by the moduleurllib to handle URLs that use FTP. For more informationon FTP (File Transfer Protocol), see InternetRFC 959.

Here's a sample session using theftplib module:

>>> from ftplib import FTP>>> ftp = FTP('ftp.cwi.nl')   # connect to host, default port>>> ftp.login()               # user anonymous, passwd user@hostname>>> ftp.retrlines('LIST')     # list directory contentstotal 24418drwxrwsr-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:

classFTP([host[, user[, passwd[, acct]]]])
Return a new instance of theFTP class. Whenhost is given, the method callconnect(host) ismade. Whenuser is given, additionally the method calllogin(user,passwd,acct) is made (wherepasswd andacct default to the empty string when not given).

all_errors
The set of all exceptions (as a tuple) that methods ofFTPinstances may raise as a result of problems with the FTP connection(as opposed to programming errors made by the caller). This setincludes the four exceptions listed below as well assocket.error andIOError.

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

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

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

exceptionerror_proto
Exception raised when a reply is received from the server that doesnot begin with a digit in the range 1-5.

See Also:

Modulenetrc:
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 fileTools/scripts/ftpmirror.py  in the Python source distribution is a script that can mirror FTP sites, or portions thereof, using theftplib module. It can be used as an extended example that applies this module.


Subsections


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:11.6.3 ExamplesUp:11. Internet Protocols andNext:11.7.1 FTP Objects
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp