class documentation

class FTP(basic.LineReceiver, policies.TimeoutMixin): (source)

View In Hierarchy

Protocol Interpreter for the File Transfer Protocol
Method cleanup​DTP Call when DTP connection exits
Method connection​Lost Called when the connection is shut down.
Method connection​Made Called when a connection is made.
Method ftp_​CDUP Undocumented
Method ftp_​CWD Undocumented
Method ftp_​DELE Undocumented
Method ftp_​FEAT Advertise the features supported by the server.
Method ftp_​LIST No summary
Method ftp_​MDTM File Modification Time (MDTM)
Method ftp_​MKD Undocumented
Method ftp_​MODE Undocumented
Method ftp_​NLST No summary
Method ftp_​NOOP Undocumented
Method ftp_​OPTS Handle OPTS command.
Method ftp_​PASS Second part of login. Get the password the peer wants to authenticate with.
Method ftp_​PASV Request for a passive connection
Method ftp_​PORT Undocumented
Method ftp_​PWD Undocumented
Method ftp_​QUIT Undocumented
Method ftp_​RETR This command causes the content of a file to be sent over the data transfer channel. If the path is to a folder, an error will be raised.
Method ftp_​RMD Undocumented
Method ftp_​RNFR Undocumented
Method ftp_​RNTO Undocumented
Method ftp_​SIZE File SIZE
Method ftp_​STOR STORE (STOR)
Method ftp_​STRU Undocumented
Method ftp_​SYST Undocumented
Method ftp_​TYPE REPRESENTATION TYPE (TYPE)
Method ftp_​USER First part of login. Get the username the peer wants to authenticate as.
Method get​DTPPort Return a port for passive access, using self.passivePortRange attribute.
Method line​Received Override this for when each line is received.
Method process​Command Undocumented
Method reply Undocumented
Method send​Line (Private) Encodes and sends a line
Method timeout​Connection Called when the connection times out.
Method type_​A Undocumented
Method type_​I Undocumented
Method type_​UNKNOWN Undocumented
Constant AUTHED Command channel was successfully authenticated.
Constant FEATURES Undocumented
Constant INAUTH Command channel is in the process of being authenticated.
Constant PUBLIC​_COMMANDS Undocumented
Constant RENAMING Command channel is between the renaming command sequence.
Constant UNAUTH Command channel is not yet authenticated.
Class Variable dtp​Timeout Undocumented
Class Variable portal Undocumented
Instance Variable binary The transfer mode. If false, ASCII.
Instance Variable disconnected Undocumented
Instance Variable dtp​Factory Generates a single DTP for this session
Instance Variable dtp​Instance Undocumented
Instance Variable dtp​Port Port returned from listenTCP
Instance Variable listen​Factory A callable with the signature of twisted.internet.interfaces.IReactorTCP.listenTCP which will be used to create Ports for passive connections (mainly for testing).
Instance Variable passive​Port​Range iterator used as source of passive port numbers.
Instance Variable shell The connected avatar
Instance Variable state The current server state. One of UNAUTH, INAUTH, AUTHED, RENAMING.
Instance Variable transport Undocumented
Method _encode​Name Encode name to be sent over the wire.
Class Variable _encoding Undocumented
Instance Variable _from​Name Undocumented
Instance Variable _user Undocumented

Inherited from LineReceiver:

Method clear​Line​Buffer Clear buffered data.
Method data​Received Protocol.dataReceived. Translates bytes into lines, and calls lineReceived (or rawDataReceived, depending on mode.)
Method line​Length​Exceeded Called when the maximum line length has been reached. Override if it needs to be dealt with in some special way.
Method raw​Data​Received Override this for when raw data is received.
Method set​Line​Mode Sets the line-mode of this receiver.
Method set​Raw​Mode Sets the raw mode of this receiver. Further data received will be sent to rawDataReceived rather than lineReceived.
Constant MAX​_LENGTH 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​_mode Undocumented
Instance Variable _buffer Undocumented
Instance Variable _busy​Receiving Undocumented

Inherited from Protocol (via LineReceiver):

Method log​Prefix Return a prefix matching the class name, to identify log messages related to this protocol instance.
Class Variable factory Undocumented

Inherited from BaseProtocol (via LineReceiver, Protocol):

Method make​Connection Make a connection to a transport and a server.
Instance Variable connected Undocumented

Inherited from _PauseableMixin (via LineReceiver):

Method pause​Producing Undocumented
Method resume​Producing Undocumented
Method stop​Producing Undocumented
Instance Variable paused Undocumented

Inherited from TimeoutMixin:

Method call​Later Wrapper around reactor.callLater for test purpose.
Method reset​Timeout Reset the timeout count down.
Method set​Timeout Change the timeout period
Instance Variable time​Out The number of seconds after which to timeout the connection.
Method __timed​Out Undocumented
Instance Variable __timeout​Call Undocumented
def cleanupDTP(self): (source)
Call when DTP connection exits
def connectionLost(self, reason): (source)

Called when the connection is shut down.

Clear any circular references here, and any external references to this Protocol. The connection has been closed.

Parameters
reason:twisted.python.failure.FailureUndocumented
def connectionMade(self): (source)

Called when a connection is made.

This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

def ftp_CDUP(self): (source)

Undocumented

def ftp_CWD(self, path): (source)

Undocumented

def ftp_DELE(self, path): (source)

Undocumented

def ftp_FEAT(self): (source)

Advertise the features supported by the server.

http://tools.ietf.org/html/rfc2389

def ftp_LIST(self, path=''): (source)
This command causes a list to be sent from the server to the passive DTP. If the pathname specifies a directory or other group of files, the server should transfer a list of files in the specified directory. If the pathname specifies a file then the server should send current information on the file. A null argument implies the user's current working or default directory.
def ftp_MDTM(self, path): (source)

File Modification Time (MDTM)

The FTP command, MODIFICATION TIME (MDTM), can be used to determine when a file in the server NVFS was last modified. This command has existed in many FTP servers for many years, as an adjunct to the REST command for STREAM mode, thus is widely available. However, where supported, the "modify" fact that can be provided in the result from the new MLST command is recommended as a superior alternative.

http://tools.ietf.org/html/rfc3659

def ftp_MKD(self, path): (source)

Undocumented

def ftp_MODE(self, mode): (source)

Undocumented

def ftp_NLST(self, path): (source)
This command causes a directory listing to be sent from the server to the client. The pathname should specify a directory or other system-specific file group descriptor. An empty path implies the current working directory. If the path is non-existent, send nothing. If the path is to a file, send only the file name.
Parameters
path:strThe path for which a directory listing should be returned.
Returns
Deferreda Deferred which will be fired when the listing request is finished.
def ftp_NOOP(self): (source)

Undocumented

def ftp_OPTS(self, option): (source)

Handle OPTS command.

http://tools.ietf.org/html/draft-ietf-ftpext-utf-8-option-00

def ftp_PASS(self, password): (source)
Second part of login. Get the password the peer wants to authenticate with.
def ftp_PASV(self): (source)

Request for a passive connection

from the rfc:

    This command requests the server-DTP to "listen" on a data port
    (which is not its default data port) and to wait for a connection
    rather than initiate one upon receipt of a transfer command.  The
    response to this command includes the host and port address this
    server is listening on.
def ftp_PORT(self, address): (source)

Undocumented

def ftp_PWD(self): (source)

Undocumented

def ftp_QUIT(self): (source)

Undocumented

def ftp_RETR(self, path): (source)
This command causes the content of a file to be sent over the data transfer channel. If the path is to a folder, an error will be raised.
Parameters
path:strThe path to the file which should be transferred over the data transfer channel.
Returns
Deferreda Deferred which will be fired when the transfer is done.
def ftp_RMD(self, path): (source)

Undocumented

def ftp_RNFR(self, fromName): (source)

Undocumented

def ftp_RNTO(self, toName): (source)

Undocumented

def ftp_SIZE(self, path): (source)

File SIZE

The FTP command, SIZE OF FILE (SIZE), is used to obtain the transfer size of a file from the server-FTP process. This is the exact number of octets (8 bit bytes) that would be transmitted over the data connection should that file be transmitted. This value will change depending on the current STRUcture, MODE, and TYPE of the data connection or of a data connection that would be created were one created now. Thus, the result of the SIZE command is dependent on the currently established STRU, MODE, and TYPE parameters.

The SIZE command returns how many octets would be transferred if the file were to be transferred using the current transfer structure, mode, and type. This command is normally used in conjunction with the RESTART (REST) command when STORing a file to a remote server in STREAM mode, to determine the restart point. The server-PI might need to read the partially transferred file, do any appropriate conversion, and count the number of octets that would be generated when sending the file in order to correctly respond to this command. Estimates of the file transfer size MUST NOT be returned; only precise information is acceptable.

http://tools.ietf.org/html/rfc3659

def ftp_STOR(self, path): (source)

STORE (STOR)

This command causes the server-DTP to accept the data transferred via the data connection and to store the data as a file at the server site. If the file specified in the pathname exists at the server site, then its contents shall be replaced by the data being transferred. A new file is created at the server site if the file specified in the pathname does not already exist.

def ftp_STRU(self, structure): (source)

Undocumented

def ftp_SYST(self): (source)

Undocumented

def ftp_TYPE(self, type): (source)

REPRESENTATION TYPE (TYPE)

The argument specifies the representation type as described in the Section on Data Representation and Storage. Several types take a second parameter. The first parameter is denoted by a single Telnet character, as is the second Format parameter for ASCII and EBCDIC; the second parameter for local byte is a decimal integer to indicate Bytesize. The parameters are separated by a <SP> (Space, ASCII code 32).

def ftp_USER(self, username): (source)
First part of login. Get the username the peer wants to authenticate as.
def getDTPPort(self, factory): (source)
Return a port for passive access, using self.passivePortRange attribute.
def lineReceived(self, line): (source)
Override this for when each line is received.
Parameters
line:bytesThe line which was received with the delimiter removed.
def processCommand(self, cmd, *params): (source)

Undocumented

def reply(self, key, *args): (source)

Undocumented

def sendLine(self, line): (source)
(Private) Encodes and sends a line
Parameters
linebytes or unicode
def timeoutConnection(self): (source)

Called when the connection times out.

Override to define behavior other than dropping the connection.

def type_A(self, code): (source)

Undocumented

def type_I(self, code): (source)

Undocumented

def type_UNKNOWN(self, code): (source)

Undocumented

AUTHED: int = (source)
Command channel was successfully authenticated.
FEATURES: list[str] = (source)

Undocumented

Value
['FEAT', 'MDTM', 'PASV', 'SIZE', 'TYPE A;I']
INAUTH: int = (source)
Command channel is in the process of being authenticated.
PUBLIC_COMMANDS: list[str] = (source)

Undocumented

Value
['FEAT', 'QUIT']
RENAMING: int = (source)
Command channel is between the renaming command sequence.
UNAUTH: int = (source)
Command channel is not yet authenticated.
dtpTimeout: int = (source)

Undocumented

portal = (source)

Undocumented

binary: bool = (source)
The transfer mode. If false, ASCII.
disconnected: bool = (source)

Undocumented

dtpFactory = (source)
Generates a single DTP for this session
dtpInstance = (source)

Undocumented

dtpPort = (source)
Port returned from listenTCP
listenFactory = (source)
A callable with the signature of twisted.internet.interfaces.IReactorTCP.listenTCP which will be used to create Ports for passive connections (mainly for testing).
passivePortRange: iterator = (source)
iterator used as source of passive port numbers.
shell = (source)
The connected avatar
state = (source)
The current server state. One of UNAUTH, INAUTH, AUTHED, RENAMING.
def _encodeName(self, name): (source)

Encode name to be sent over the wire.

This encodes unicode objects as UTF-8 and leaves bytes as-is.

As described by RFC 3659 section 2.2:

    Various FTP commands take pathnames as arguments, or return
    pathnames in responses. When the MLST command is supported, as
    indicated in the response to the FEAT command, pathnames are to be
    transferred in one of the following two formats.

        pathname = utf-8-name / raw
        utf-8-name = <a UTF-8 encoded Unicode string>
        raw = <any string that is not a valid UTF-8 encoding>

    Which format is used is at the option of the user-PI or server-PI
    sending the pathname.
Parameters
name:bytes or unicodeName to be encoded.
Returns
bytesWire format of name.
_encoding: str = (source)

Undocumented

_fromName = (source)

Undocumented

_user = (source)

Undocumented