Several methods are available in two flavors: one for handling text files and another for binary files. These are named for the command which is used followed by "lines" for the text version or "binary" for the binary version.
FTP instances have the following methods:
0
, produces no
debugging output. A value of 1
produces a moderate amount of
debugging output, generally a single line per request. A value of
2
or higher produces the maximum amount of debugging output,
logging each line sent and received on the control connection.
21
, as
specified by the FTP protocol specification. It is rarely needed to
specify a different port number. This function should be called only
once for each instance; it should not be called at all if a host was
given when the instance was created. All other methods can only be
used after a connection has been made.
'anonymous'
. If
user is 'anonymous'
, the default passwd is
"realuser@host" where realuser is the real user
name (glanced from the LOGNAME or USER environment
variable) and host is the hostname as returned by
socket.gethostname(). This function should be called only
once for each instance, after a connection has been established; it
should not be called at all if a host and user were given when the
instance was created. Most FTP commands are only allowed after the
client has logged in.
'RETR filename'
.
The callback function is called for each block of data received,
with a single string argument giving the data block.
The optional maxblocksize argument specifies the maximum chunk size to
read on the low-level socket object created to do the actual transfer
(which will also be the largest size of the data blocks passed to
callback). A reasonable default is chosen. rest means the
same thing as in the transfercmd() method.
'LIST'
). The callback function is called for each line,
with the trailing CRLF stripped. The default callback prints
the line to sys.stdout
.
"STOR filename"
.
file is an open file object which is read until EOF using its
read() method in blocks of size blocksize to provide the
data to be stored. The blocksize argument defaults to 8192.
Changed in version 2.1:
default for blocksize added.
If optional rest is given, a "REST" command is sent to the server, passing rest as an argument. rest is usually a byte offset into the requested file, telling the server to restart sending the file's bytes at the requested offset, skipping over the initial bytes. Note however that RFC 959 requires only that rest be a string containing characters in the printable range from ASCII code 33 to ASCII code 126. The transfercmd() method, therefore, converts rest to a string, but no check is performed on the string's contents. If the server does not recognize the "REST" command, an error_reply exception will be raised. If this happens, simply call transfercmd() without a rest argument.
None
will be returned as the expected
size. cmd and rest means the same thing as in
transfercmd().
sys.stdout
. This method returns None
.
None
is returned. Note that the "SIZE" command is not
standardized, but is supported by many common server implementations.