Package twisted :: Package protocols :: Module ftp :: Class FTPClient |
[show private | hide private]
[frames | no frames]

## Class FTPClient

    BaseProtocol --+
                   |
            Protocol --+
                       |
            LineReceiver --+
                           |
                          FTPClient

A Twisted FTP Client

Supports active and passive transfers.

This class is semi-stable.

Method Summary
| ``__init__`(self, username, password, passive)` Constructor.
| ``cdup`(self)` Issues the CDUP (Change Directory UP) command.
| ``connectionFailed`(self)` (Deprecated) (inherited from `Protocol`)
| ``connectionLost`(self, reason)` Called when the connection is shut down. (inherited from `Protocol`)
| ``connectionMade`(self)` Called when a connection is made. (inherited from `BaseProtocol`)
| ``cwd`(self, path)` Issues the CWD (Change Working Directory) command.
| ``dataReceived`(self, data)` Protocol.dataReceived. (inherited from `LineReceiver`)
| ``escapePath`(self, path)` Returns a FTP escaped path (replace newlines with nulls)
| ``fail`(self, error)` Disconnect, and also give an error to any queued deferreds.
| ``generatePortCommand`(self, portCmd)` (Private) Generates the text of a given PORT command
| ``lineLengthExceeded`(self, line)` Called when the maximum line length has been reached. (inherited from `LineReceiver`)
| ``lineReceived`(self, line)` (Private) Parses the response messages from the FTP server.
| ``list`(self, path, protocol)` Retrieve a file listing into the given protocol instance.
| ``makeConnection`(self, transport)` Make a connection to a transport and a server. (inherited from `BaseProtocol`)
| ``nlst`(self, path, protocol)` Retrieve a short file listing into the given protocol instance.
| ``popCommandQueue`(self)` Return the front element of the command queue, or None if empty.
| ``pwd`(self)` Issues the PWD (Print Working Directory) command.
| ``queueCommand`(self, ftpCommand)` Add an FTPCommand object to the queue.
| ``queueLogin`(self)` Initialise the connection.
| ``queueStringCommand`(self, command, public)` Queues a string to be issued as an FTP command
| ``quit`(self)` Issues the QUIT command.
| ``rawDataReceived`(self, data)` Override this for when raw data is received. (inherited from `LineReceiver`)
| ``receiveFromConnection`(self, command, protocol)` Retrieves a file or listing generated by the given command, feeding it to the given protocol.
| ``retr`(self, path, protocol)` Retrieve a file from the given path
| ``retrieveFile`(self, path, protocol)` Retrieve a file from the given path
| ``sendLine`(self, line)` (Private) Sends a line, unless line is None.
| ``sendNextCommand`(self)` (Private) Processes the next command in the queue.
| `sendToConnection(self, command)`
| ``setLineMode`(self, extra)` Sets the line-mode of this receiver. (inherited from `LineReceiver`)
| ``setRawMode`(self)` Sets the raw mode of this receiver. (inherited from `LineReceiver`)
| ``stor`(self, path)` Store a file at the given path.
| ``storeFile`(self, path)` Store a file at the given path.
| ``_openDataConnection`(self, command, protocol)` This method *twitch* returns a list of Deferreds *twitch* but the last element is a DeferredList based on the elements prior to *twitch* it.

Instance Variable Summary
| `passive` - See description in __init__.

Class Variable Summary
`int` | `debug`

Method Details

### __init__(self, username='anonymous', password='twisted@twistedmatrix.com', passive=1) (Constructor) 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.

### cdup(self) Issues the CDUP (Change Directory UP) command. Returns: a `Deferred` that will be called when done.

### cwd(self, path) Issues the CWD (Change Working Directory) command. Returns: a `Deferred` that will be called when done.

### escapePath(self, path) Returns a FTP escaped path (replace newlines with nulls)

### fail(self, error) Disconnect, and also give an error to any queued deferreds.

### generatePortCommand(self, portCmd) (Private) Generates the text of a given PORT command

### lineReceived(self, line) (Private) Parses the response messages from the FTP server.

### list(self, path, protocol) 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`

### nlst(self, path, protocol) 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.

### popCommandQueue(self) Return the front element of the command queue, or None if empty.

### pwd(self) Issues the PWD (Print Working Directory) command. 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.

### queueCommand(self, ftpCommand) Add an FTPCommand object to the queue. If it's the only thing in the queue, and we are connected and we aren't waiting for a response of an earlier command, the command will be sent immediately. Parameters: `ftpCommand` - an `FTPCommand`

### queueLogin(self) Initialise the connection. Login, send the password, set retrieval mode to binary

### queueStringCommand(self, command, public=1) Queues a string to be issued as an FTP command Parameters: `command` - string of an FTP command to queue `public` - a flag intended for internal use by FTPClient. Don't change it unless you know what you're doing. Returns: a `Deferred` that will be called when the response to the command has been received.

### quit(self) Issues the QUIT command.

### receiveFromConnection(self, command, protocol) Retrieves a file or listing generated by the given command, feeding it to the given protocol. Parameters: `command` - string of an FTP command to execute then receive the results of (e.g. LIST, RETR) `protocol` - A `Protocol` *instance*, or something that can be adapted to one e.g. an `FTPFileListProtocol`. Typically this will be an `IConsumer` implemenation. Returns: `Deferred`.

### retr(self, path, protocol) 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. Returns: `Deferred`

### retrieveFile(self, path, protocol) 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. Returns: `Deferred`

### sendLine(self, line) (Private) Sends a line, unless line is None.

### sendNextCommand(self) (Private) Processes the next command in the queue.

### stor(self, path) Store a file at the given path. This method issues the 'STOR' FTP command. Returns: A tuple of two `Deferred`s: `Deferred` `IFinishableConsumer`. You must call the `finish` method on the IFinishableConsumer when the file is completely transferred. `Deferred` list of control-connection responses.

### storeFile(self, path) Store a file at the given path. This method issues the 'STOR' FTP command. Returns: A tuple of two `Deferred`s: `Deferred` `IFinishableConsumer`. You must call the `finish` method on the IFinishableConsumer when the file is completely transferred. `Deferred` list of control-connection responses.

### _openDataConnection(self, command, protocol) This method *twitch* returns a list of Deferreds *twitch* but the last element is a DeferredList based on the elements prior to *twitch* it.

Instance Variable Details

### passive See description in __init__.

Class Variable Details

    ### debug Type: `int` Value:
        0

Generated by Epydoc 1.1 on Thu May 8 13:18:37 2003 | http://epydoc.sf.net