class FTPClient(FTPClientBasic): (source)
Constructor: FTPClient(username, password, passive)
FTPClient
is a client implementation of the FTP protocol which exposes FTP commands as methods which return Deferred
s.
Each command method returns a Deferred
which is called back when a successful response code (2xx or 3xx) is received from the server or which is error backed if an error response code (4xx or 5xx) is received from the server or if a protocol violation occurs. If an error response code is received, the Deferred
fires with a Failure
wrapping a CommandFailed
instance. The CommandFailed
instance is created with a list of the response lines received from the server.
See RFC 959 for error code definitions.
Both active and passive transfers are supported.
Method | __init__ |
Constructor. |
Method | cdup |
Issues the CDUP (Change Directory UP) command. |
Method | cwd |
Issues the CWD (Change Working Directory) command. |
Method | escape |
Returns a FTP escaped path (replace newlines with nulls). |
Method | fail |
Disconnect, and also give an error to any queued deferreds. |
Method | generate |
(Private) Generates the text of a given PORT command. |
Method | get |
Returns the current remote directory. |
Method | list |
Retrieve a file listing into the given protocol instance. |
Method | make |
Make a directory |
Method | nlst |
Retrieve a short file listing into the given protocol instance. |
Method | pwd |
Issues the PWD (Print Working Directory) command. |
Method | queue |
Login: send the username, send the password, and set retrieval mode to binary |
Method | quit |
Issues the QUIT command. |
Method | receive |
Retrieves a file or listing generated by the given command, feeding it to the given protocol. |
Method | remove |
Delete a directory on the server. |
Method | remove |
Delete a file on the server. |
Method | rename |
Rename a file. |
Method | retrieve |
Retrieve a file from the given path |
Method | send |
XXX |
Method | store |
Store a file at the given path. |
Instance Variable | passive |
See description in __init__. |
Method | _open |
This method returns a DeferredList. |
Inherited from FTPClientBasic
:
Method | connection |
Called when the connection is shut down. |
Method | line |
(Private) Parses the response messages from the FTP server. |
Method | pop |
Return the front element of the command queue, or None if empty. |
Method | queue |
Add an FTPCommand object to the queue. |
Method | queue |
Queues a string to be issued as an FTP command |
Method | send |
Sends a line, unless line is None. |
Method | send |
(Private) Processes the next command in the queue. |
Class Variable | debug |
Undocumented |
Instance Variable | action |
Undocumented |
Instance Variable | greeting |
Undocumented |
Instance Variable | next |
Undocumented |
Instance Variable | response |
Undocumented |
Method | _cb |
Undocumented |
Method | _fail |
Errback all queued deferreds. |
Class Variable | _encoding |
Undocumented |
Instance Variable | _failed |
Undocumented |
Inherited from LineReceiver
(via FTPClientBasic
):
Method | clear |
Clear buffered data. |
Method | data |
Protocol.dataReceived. Translates bytes into lines, and calls lineReceived (or rawDataReceived, depending on mode.) |
Method | line |
Called when the maximum line length has been reached. Override if it needs to be dealt with in some special way. |
Method | raw |
Override this for when raw data is received. |
Method | set |
Sets the line-mode of this receiver. |
Method | set |
Sets the raw mode of this receiver. Further data received will be sent to rawDataReceived rather than lineReceived. |
Constant | MAX |
The maximum length of a line to allow (If a sent line is longer than this, the connection is dropped). Default is 16384. |
Class Variable | delimiter |
The line-ending delimiter to use. By default this is b'\r\n'. |
Instance Variable | line |
Undocumented |
Instance Variable | _buffer |
Undocumented |
Instance Variable | _busy |
Undocumented |
Inherited from Protocol
(via FTPClientBasic
, LineReceiver
):
Method | log |
Return a prefix matching the class name, to identify log messages related to this protocol instance. |
Class Variable | factory |
Undocumented |
Inherited from BaseProtocol
(via FTPClientBasic
, LineReceiver
, Protocol
):
Method | connection |
Called when a connection is made. |
Method | make |
Make a connection to a transport and a server. |
Instance Variable | connected |
Undocumented |
Instance Variable | transport |
Undocumented |
Inherited from _PauseableMixin
(via FTPClientBasic
, LineReceiver
, Protocol
, BaseProtocol
):
Method | pause |
Undocumented |
Method | resume |
Undocumented |
Method | stop |
Undocumented |
Instance Variable | paused |
Undocumented |
Constructor.
I will login as soon as I receive the welcome message from the server.
Parameters | |
username | FTP username |
password | FTP password |
passive | flag that controls if I use active or passive data connections. You can also change this after construction by assigning to self.passive. |
Returns the current remote directory.
Returns | |
a Deferred that will be called back with a str giving the remote directory or which will errback with CommandFailed if an error response is returned. |
Retrieve a file listing into the given protocol instance.
This method issues the 'LIST' FTP command.
Parameters | |
path | path to get a file listing for. |
protocol | a Protocol instance, probably a FTPFileListProtocol instance. It can cope with most common file listing formats. |
Returns | |
Deferred |
Make a directory
This method issues the MKD command.
Parameters | |
path:str | The path to the directory to create. |
Returns | |
Deferred | A Deferred which fires when the server responds. If the directory is created, the Deferred is called back with the server response. If the server response indicates the directory was not created, the Deferred is errbacked with a Failure wrapping CommandFailed or BadResponse . |
Present Since | |
8.2 |
Retrieve a short file listing into the given protocol instance.
This method issues the 'NLST' FTP command.
NLST (should) return a list of filenames, one per line.
Parameters | |
path | path to get short file listing for. |
protocol | a Protocol instance. |
Issues the PWD (Print Working Directory) command.
The getDirectory
does the same job but automatically parses the result.
Returns | |
a Deferred that will be called when done. It is up to the caller to interpret the response, but the parsePWDResponse method in this module should work. |
Retrieves a file or listing generated by the given command, feeding it to the given protocol.
Parameters | |
commands | list of strings of FTP commands to execute then receive the results of (e.g. LIST, RETR) |
protocol | A Protocol instance e.g. an FTPFileListProtocol , or something that can be adapted to one. Typically this will be an IConsumer implementation. |
Returns | |
Deferred . |
Delete a directory on the server.
removeDirectory
issues a RMD command to the server to remove the indicated directory. Described in RFC959.
Parameters | |
path:str | The path to the directory to delete. May be relative to the current working directory. |
Returns | |
Deferred | A Deferred which fires when the server responds. On error, it is errbacked with either CommandFailed or BadResponse . On success, it is called back with a list of response lines. |
Present Since | |
11.1 |
Delete a file on the server.
removeFile
issues a DELE command to the server to remove the indicated file. Note that this command cannot remove a directory.
Parameters | |
path:str | The path to the file to delete. May be relative to the current dir. |
Returns | |
Deferred | A Deferred which fires when the server responds. On error, it is errbacked with either CommandFailed or BadResponse . On success, it is called back with a list of response lines. |
Present Since | |
8.2 |
Rename a file.
This method issues the RNFR/RNTO command sequence to rename pathFrom to pathTo.
Parameters | |
path | the absolute path to the file to be renamed |
path | the absolute path to rename the file to. |
Returns | |
Deferred | A Deferred which fires when the rename operation has succeeded or failed. If it succeeds, the Deferred is called back with a two-tuple of lists. The first list contains the responses to the RNFR command. The second list contains the responses to the RNTO command. If either RNFR or RNTO fails, the Deferred is errbacked with CommandFailed or BadResponse . |
Present Since | |
8.2 |
Retrieve a file from the given path
This method issues the 'RETR' FTP command.
The file is fed into the given Protocol instance. The data connection will be passive if self.passive is set.
Parameters | |
path | path to file that you wish to receive. |
protocol | a Protocol instance. |
offset | offset to start downloading from |
Returns | |
Deferred |
XXX
Returns | |
A tuple of two
|
Store a file at the given path.
This method issues the 'STOR' FTP command.
Returns | |
A tuple of two
|