Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{ftplib} --- |
| 2 | FTP protocol client.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | \declaremodule{standard}{ftplib} |
| 4 | |
| 5 | \modulesynopsis{FTP protocol client (requires sockets).} |
| 6 | |
Fred Drake | 15bac5d | 1998-01-07 13:13:42 +0000 | [diff] [blame] | 7 | \indexii{FTP}{protocol} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 8 | |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 9 | |
Fred Drake | 4f31694 | 1998-04-27 14:54:06 +0000 | [diff] [blame] | 10 | This module defines the class \class{FTP} and a few related items. |
| 11 | The \class{FTP} class implements the client side of the FTP protocol. |
| 12 | You can use this to write Python programs that perform a variety of |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 13 | automated FTP jobs, such as mirroring other ftp servers. It is also |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 14 | used by the module \module{urllib} to handle URLs that use FTP. For |
Fred Drake | 4f31694 | 1998-04-27 14:54:06 +0000 | [diff] [blame] | 15 | more information on FTP (File Transfer Protocol), see Internet |
| 16 | \rfc{959}. |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 17 | |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 18 | Here's a sample session using the \module{ftplib} module: |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 19 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 20 | \begin{verbatim} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 21 | >>> from ftplib import FTP |
| 22 | >>> ftp = FTP('ftp.cwi.nl') # connect to host, default port |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 23 | >>> ftp.login() # user anonymous, passwd user@hostname |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 24 | >>> ftp.retrlines('LIST') # list directory contents |
| 25 | total 24418 |
| 26 | drwxrwsr-x 5 ftp-usr pdmaint 1536 Mar 20 09:48 . |
| 27 | dr-xr-srwt 105 ftp-usr pdmaint 1536 Mar 21 14:32 .. |
| 28 | -rw-r--r-- 1 ftp-usr pdmaint 5305 Mar 20 09:48 INDEX |
| 29 | . |
| 30 | . |
| 31 | . |
Fred Drake | 161edc2 | 1998-08-07 17:30:49 +0000 | [diff] [blame] | 32 | >>> ftp.retrbinary('RETR README', open('README', 'wb').write) |
| 33 | '226 Transfer complete.' |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 34 | >>> ftp.quit() |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 35 | \end{verbatim} |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 36 | |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 37 | The module defines the following items: |
| 38 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 39 | \begin{classdesc}{FTP}{\optional{host\optional{, user\optional{, |
| 40 | passwd\optional{, acct}}}}} |
Fred Drake | 4f31694 | 1998-04-27 14:54:06 +0000 | [diff] [blame] | 41 | Return a new instance of the \class{FTP} class. When |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 42 | \var{host} is given, the method call \code{connect(\var{host})} is |
| 43 | made. When \var{user} is given, additionally the method call |
| 44 | \code{login(\var{user}, \var{passwd}, \var{acct})} is made (where |
| 45 | \var{passwd} and \var{acct} default to the empty string when not given). |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 46 | \end{classdesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 47 | |
| 48 | \begin{datadesc}{all_errors} |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 49 | The set of all exceptions (as a tuple) that methods of \class{FTP} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 50 | instances may raise as a result of problems with the FTP connection |
| 51 | (as opposed to programming errors made by the caller). This set |
| 52 | includes the four exceptions listed below as well as |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 53 | \exception{socket.error} and \exception{IOError}. |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 54 | \end{datadesc} |
| 55 | |
| 56 | \begin{excdesc}{error_reply} |
| 57 | Exception raised when an unexpected reply is received from the server. |
| 58 | \end{excdesc} |
| 59 | |
| 60 | \begin{excdesc}{error_temp} |
| 61 | Exception raised when an error code in the range 400--499 is received. |
| 62 | \end{excdesc} |
| 63 | |
| 64 | \begin{excdesc}{error_perm} |
| 65 | Exception raised when an error code in the range 500--599 is received. |
| 66 | \end{excdesc} |
| 67 | |
| 68 | \begin{excdesc}{error_proto} |
| 69 | Exception raised when a reply is received from the server that does |
| 70 | not begin with a digit in the range 1--5. |
| 71 | \end{excdesc} |
| 72 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 73 | |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 74 | \subsection{FTP Objects} |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 75 | \label{ftp-objects} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 76 | |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 77 | \class{FTP} instances have the following methods: |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 78 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 79 | \begin{methoddesc}{set_debuglevel}{level} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 80 | Set the instance's debugging level. This controls the amount of |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 81 | debugging output printed. The default, \code{0}, produces no |
| 82 | debugging output. A value of \code{1} produces a moderate amount of |
| 83 | debugging output, generally a single line per request. A value of |
| 84 | \code{2} or higher produces the maximum amount of debugging output, |
| 85 | logging each line sent and received on the control connection. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 86 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 87 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 88 | \begin{methoddesc}{connect}{host\optional{, port}} |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 89 | Connect to the given host and port. The default port number is \code{21}, as |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 90 | specified by the FTP protocol specification. It is rarely needed to |
| 91 | specify a different port number. This function should be called only |
| 92 | once for each instance; it should not be called at all if a host was |
| 93 | given when the instance was created. All other methods can only be |
| 94 | used after a connection has been made. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 95 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 96 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 97 | \begin{methoddesc}{getwelcome}{} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 98 | Return the welcome message sent by the server in reply to the initial |
| 99 | connection. (This message sometimes contains disclaimers or help |
| 100 | information that may be relevant to the user.) |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 101 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 102 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 103 | \begin{methoddesc}{login}{\optional{user\optional{, passwd\optional{, acct}}}} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 104 | Log in as the given \var{user}. The \var{passwd} and \var{acct} |
| 105 | parameters are optional and default to the empty string. If no |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 106 | \var{user} is specified, it defaults to \code{'anonymous'}. If |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 107 | \var{user} is \code{anonymous}, the default \var{passwd} is |
| 108 | \samp{\var{realuser}@\var{host}} where \var{realuser} is the real user |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 109 | name (glanced from the \envvar{LOGNAME} or \envvar{USER} environment |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 110 | variable) and \var{host} is the hostname as returned by |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 111 | \function{socket.gethostname()}. This function should be called only |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 112 | once for each instance, after a connection has been established; it |
| 113 | should not be called at all if a host and user were given when the |
| 114 | instance was created. Most FTP commands are only allowed after the |
| 115 | client has logged in. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 116 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 117 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 118 | \begin{methoddesc}{abort}{} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 119 | Abort a file transfer that is in progress. Using this does not always |
| 120 | work, but it's worth a try. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 121 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 122 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 123 | \begin{methoddesc}{sendcmd}{command} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 124 | Send a simple command string to the server and return the response |
| 125 | string. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 126 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 127 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 128 | \begin{methoddesc}{voidcmd}{command} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 129 | Send a simple command string to the server and handle the response. |
| 130 | Return nothing if a response code in the range 200--299 is received. |
| 131 | Raise an exception otherwise. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 132 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 133 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 134 | \begin{methoddesc}{retrbinary}{command, callback\optional{, maxblocksize}} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 135 | Retrieve a file in binary transfer mode. \var{command} should be an |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 136 | appropriate \samp{RETR} command, i.e.\ \code{'RETR \var{filename}'}. |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 137 | The \var{callback} function is called for each block of data received, |
| 138 | with a single string argument giving the data block. |
Guido van Rossum | ab76af3 | 1997-12-03 19:34:14 +0000 | [diff] [blame] | 139 | The optional \var{maxblocksize} argument specifies the maximum chunk size to |
| 140 | read on the low-level socket object created to do the actual transfer |
| 141 | (which will also be the largest size of the data blocks passed to |
| 142 | \var{callback}). A reasonable default is chosen. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 143 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 144 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 145 | \begin{methoddesc}{retrlines}{command\optional{, callback}} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 146 | Retrieve a file or directory listing in \ASCII{} transfer mode. |
Fred Drake | 4b3f031 | 1996-12-13 22:04:31 +0000 | [diff] [blame] | 147 | \var{command} should be an appropriate \samp{RETR} command (see |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 148 | \method{retrbinary()} or a \samp{LIST} command (usually just the string |
| 149 | \code{'LIST'}). The \var{callback} function is called for each line, |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 150 | with the trailing CRLF stripped. The default \var{callback} prints |
| 151 | the line to \code{sys.stdout}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 152 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 153 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 154 | \begin{methoddesc}{storbinary}{command, file, blocksize} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 155 | Store a file in binary transfer mode. \var{command} should be an |
| 156 | appropriate \samp{STOR} command, i.e.\ \code{"STOR \var{filename}"}. |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 157 | \var{file} is an open file object which is read until \EOF{} using its |
| 158 | \method{read()} method in blocks of size \var{blocksize} to provide the |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 159 | data to be stored. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 160 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 161 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 162 | \begin{methoddesc}{storlines}{command, file} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 163 | Store a file in \ASCII{} transfer mode. \var{command} should be an |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 164 | appropriate \samp{STOR} command (see \method{storbinary()}). Lines are |
| 165 | read until \EOF{} from the open file object \var{file} using its |
| 166 | \method{readline()} method to privide the data to be stored. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 167 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 168 | |
Fred Drake | 4f31694 | 1998-04-27 14:54:06 +0000 | [diff] [blame] | 169 | \begin{methoddesc}{transfercmd}{cmd} |
| 170 | Initiate a transfer over the data connection. If the transfer is |
| 171 | active, send a \samp{PORT} command and the transfer command specified |
| 172 | by \var{cmd}, and accept the connection. If the server is passive, |
| 173 | send a \samp{PASV} command, connect to it, and start the transfer |
| 174 | command. Either way, return the socket for the connection. |
| 175 | \end{methoddesc} |
| 176 | |
| 177 | \begin{methoddesc}{ntransfercmd}{cmd} |
| 178 | Like \method{transfercmd()}, but returns a tuple of the data |
| 179 | connection and the expected size of the data. If the expected size |
| 180 | could not be computed, \code{None} will be returned as the expected |
| 181 | size. |
| 182 | \end{methoddesc} |
| 183 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 184 | \begin{methoddesc}{nlst}{argument\optional{, \ldots}} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 185 | Return a list of files as returned by the \samp{NLST} command. The |
Fred Drake | 4b3f031 | 1996-12-13 22:04:31 +0000 | [diff] [blame] | 186 | optional \var{argument} is a directory to list (default is the current |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 187 | server directory). Multiple arguments can be used to pass |
| 188 | non-standard options to the \samp{NLST} command. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 189 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 190 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 191 | \begin{methoddesc}{dir}{argument\optional{, \ldots}} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 192 | Return a directory listing as returned by the \samp{LIST} command, as |
Fred Drake | 4b3f031 | 1996-12-13 22:04:31 +0000 | [diff] [blame] | 193 | a list of lines. The optional \var{argument} is a directory to list |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 194 | (default is the current server directory). Multiple arguments can be |
| 195 | used to pass non-standard options to the \samp{LIST} command. If the |
| 196 | last argument is a function, it is used as a \var{callback} function |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 197 | as for \method{retrlines()}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 198 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 199 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 200 | \begin{methoddesc}{rename}{fromname, toname} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 201 | Rename file \var{fromname} on the server to \var{toname}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 202 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 203 | |
Fred Drake | 4f31694 | 1998-04-27 14:54:06 +0000 | [diff] [blame] | 204 | \begin{methoddesc}{delete}{filename} |
| 205 | Remove the file named \var{filename} from the server. If successful, |
| 206 | returns the text of the response, otherwise raises |
| 207 | \exception{error_perm} on permission errors or \exception{error_reply} |
| 208 | on other errors. |
| 209 | \end{methoddesc} |
| 210 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 211 | \begin{methoddesc}{cwd}{pathname} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 212 | Set the current directory on the server. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 213 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 214 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 215 | \begin{methoddesc}{mkd}{pathname} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 216 | Create a new directory on the server. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 217 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 218 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 219 | \begin{methoddesc}{pwd}{} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 220 | Return the pathname of the current directory on the server. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 221 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 222 | |
Fred Drake | 4f31694 | 1998-04-27 14:54:06 +0000 | [diff] [blame] | 223 | \begin{methoddesc}{rmd}{dirname} |
| 224 | Remove the directory named \var{dirname} on the server. |
| 225 | \end{methoddesc} |
| 226 | |
| 227 | \begin{methoddesc}{size}{filename} |
| 228 | Request the size of the file named \var{filename} on the server. On |
| 229 | success, the size of the file is returned as an integer, otherwise |
| 230 | \code{None} is returned. Note that the \samp{SIZE} command is not |
| 231 | standardized, but is supported by many common server implementations. |
| 232 | \end{methoddesc} |
| 233 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 234 | \begin{methoddesc}{quit}{} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 235 | Send a \samp{QUIT} command to the server and close the connection. |
| 236 | This is the ``polite'' way to close a connection, but it may raise an |
Fred Drake | 6a1eefe | 1998-03-12 06:04:53 +0000 | [diff] [blame] | 237 | exception of the server reponds with an error to the \samp{QUIT} |
Guido van Rossum | 730d837 | 1998-08-07 17:36:59 +0000 | [diff] [blame] | 238 | command. This implies a call to the \method{close()} method which |
| 239 | renders the \class{FTP} instance useless for subsequent calls (see |
| 240 | below). |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 241 | \end{methoddesc} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 242 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 243 | \begin{methoddesc}{close}{} |
Guido van Rossum | cca8d2b | 1995-03-22 15:48:46 +0000 | [diff] [blame] | 244 | Close the connection unilaterally. This should not be applied to an |
| 245 | already closed connection (e.g.\ after a successful call to |
Guido van Rossum | 730d837 | 1998-08-07 17:36:59 +0000 | [diff] [blame] | 246 | \method{quit()}. After this call the \class{FTP} instance should not |
| 247 | be used any more (i.e., after a call to \method{close()} or |
| 248 | \method{quit()} you cannot reopen the connection by issueing another |
| 249 | \method{login()} method). |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 250 | \end{methoddesc} |