twisted.protocols.ftp.FTPClient

Package twisted :: Package protocols :: Module ftp :: Class FTPClient |
[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.
| ``_fail`(self, error)` Errback all queued deferreds.
| ``_openDataConnection`(self, commands, protocol)` This method returns a DeferredList.
| ``cdup`(self)` Issues the CDUP (Change Directory UP) command.
| `connectionLost(self, reason)`
| ``cwd`(self, path)` Issues the CWD (Change Working Directory) command.
| ``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.
| ``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.
| ``receiveFromConnection`(self, commands, protocol)` Retrieves a file or listing generated by the given command, feeding it to the given protocol.
| ``retr`(self, path, protocol, offset)` Retrieve a file from the given path
| ``retrieveFile`(self, path, protocol, offset)` 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, commands)` XXX
| ``stor`(self, path, offset)` Store a file at the given path.
| ``storeFile`(self, path, offset)` Store a file at the given path.
Inherited from LineReceiver
| ``clearLineBuffer`(self)` Clear buffered data.
| ``dataReceived`(self, data)` Protocol.dataReceived.
| ``lineLengthExceeded`(self, line)` Called when the maximum line length has been reached.
| ``rawDataReceived`(self, data)` Override this for when raw data is received.
| ``setLineMode`(self, extra)` Sets the line-mode of this receiver.
| ``setRawMode`(self)` Sets the raw mode of this receiver.
Inherited from Protocol
| ``connectionFailed`(self)` (Deprecated)
Inherited from BaseProtocol
| ``connectionMade`(self)` Called when a connection is made.
| ``makeConnection`(self, transport)` Make a connection to a transport and a server.

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

Class Variable Summary
`int` | `debug` = 0
Inherited from LineReceiver
`str` | `_LineReceiver__buffer` = `''`
`str` | `delimiter`: The line-ending delimiter to use.
`int` | `line_mode` = 1
`int` | `MAX_LENGTH`: The maximum length of a line to allow (If a sent line is longer than this, the connection is dropped).
Inherited from Protocol
`tuple` | `__implements__` = `(<class twisted.internet.interfaces.IPr...`
Inherited from BaseProtocol
`int` | `connected` = 0
`NoneType` | `transport` = None

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.

### _fail(self, error) Errback all queued deferreds.

### _openDataConnection(self, commands, protocol) This method returns a DeferredList.

### 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. Overrides: `twisted.protocols.basic.LineReceiver.lineReceived`

### 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, commands, protocol) Retrieves a file or listing generated by the given command, feeding it to the given protocol. Parameters: `protocol` - A `Protocol` *instance* e.g. an `FTPFileListProtocol`, or something that can be adapted to one. Typically this will be an `IConsumer` implemenation. Returns: `Deferred`.

### retr(self, path, protocol, offset=0) 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`

### retrieveFile(self, path, protocol, offset=0) 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`

### sendLine(self, line) (Private) Sends a line, unless line is None. Overrides: `twisted.protocols.basic.LineReceiver.sendLine`

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

### sendToConnection(self, commands) XXX 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.

### stor(self, path, offset=0) 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, offset=0) 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.

Instance Variable Details

### passive See description in __init__.

Class Variable Details

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

Generated by Epydoc 2.0 on Sat May 15 20:08:49 2004 | http://epydoc.sf.net