twisted.protocols.ftp.FTPFileListProtocol

Package twisted :: Package protocols :: Module ftp :: Class FTPFileListProtocol |
[frames | no frames]

## Class FTPFileListProtocol

    BaseProtocol --+
                   |
            Protocol --+
                       |
            LineReceiver --+
                           |
                          FTPFileListProtocol

Parser for standard FTP file listings

This is the evil required to match:

       -rw-r--r--   1 root     other        531 Jan 29 03:26 README

If you need different evil for a wacky FTP server, you can override either `fileLinePattern` or `parseDirectoryLine()`.

It populates the instance attribute self.files, which is a list containing dicts with the following keys (examples from the above line):

- filetype: e.g. 'd' for directories, or '-' for an ordinary file
- perms: e.g. 'rw-r--r--'
- nlinks: e.g. 1
- owner: e.g. 'root'
- group: e.g. 'other'
- size: e.g. 531
- date: e.g. 'Jan 29 03:26'
- filename: e.g. 'README'
- linktarget: e.g. 'some/file'

Note that the 'date' value will be formatted differently depending on the date. Check http://cr.yp.to/ftp.html if you really want to try to parse it.

Method Summary
| `__init__(self)`
| ``addFile`(self, info)` Append file information dictionary to the list of known files.
| ``lineReceived`(self, line)` Override this for when each line is received.
| ``parseDirectoryLine`(self, line)` Return a dictionary of fields, or None if line cannot be parsed.
| ``unknownLine`(self, line)` Deal with received lines which could not be parsed as file information.
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.
| ``sendLine`(self, line)` Sends a line to the other end of the connection.
| ``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)
| ``connectionLost`(self, reason)` Called when the connection is shut down.
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
| `files`: list of dicts describing the files in this listing

Class Variable Summary
`str` | `delimiter`: The line-ending delimiter to use.
`SRE_Pattern` | `fileLinePattern` = `^(.)(.{9})\s+(\d*)\s*(\S+)\s+(\S+)\s+(...`
Inherited from LineReceiver
`str` | `_LineReceiver__buffer` = `''`
`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

### addFile(self, info) Append file information dictionary to the list of known files. Subclasses can override or extend this method to handle file information differently without affecting the parsing of data from the server. Parameters: `info` - dictionary containing the parsed representation of the file information (type=dict)

### lineReceived(self, line) Override this for when each line is received. Overrides: `twisted.protocols.basic.LineReceiver.lineReceived` (inherited documentation)

### parseDirectoryLine(self, line) Return a dictionary of fields, or None if line cannot be parsed. Parameters: `line` - line of text expected to contain a directory entry (type=str) Returns: dict

### unknownLine(self, line) Deal with received lines which could not be parsed as file information. Subclasses can override this to perform any special processing needed. Parameters: `line` - unparsable line as received (type=str)

Instance Variable Details

### files list of dicts describing the files in this listing

Class Variable Details

    ### delimiter The line-ending delimiter to use. By default this is '\r\n'. Type: `str` Value:
        '''
        '''

    ### fileLinePattern Type: `SRE_Pattern` Value:
        ^(.)(.{9})\s+(\d*)\s*(\S+)\s+(\S+)\s+(\d+)\s+(...\s+\d+\s+[\d:]+)\s+((\
        [^ ]|\\ )*?)( -> ([^\r]*))?\r?$

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