class FTP(basic.LineReceiver, policies.TimeoutMixin): (source)
Protocol Interpreter for the File Transfer Protocol
Method | cleanup |
Call when DTP connection exits |
Method | connection |
Called when the connection is shut down. |
Method | connection |
Called when a connection is made. |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Extended request for a data connection. |
Method | ftp_ |
Extended request for a passive connection. |
Method | ftp_ |
Advertise the features supported by the server. |
Method | ftp_ |
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... |
Method | ftp_ |
File Modification Time (MDTM) |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Undocumented |
Method | ftp_ |
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... |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Handle OPTS command. |
Method | ftp_ |
Second part of login. Get the password the peer wants to authenticate with. |
Method | ftp_ |
Request for a passive connection |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Undocumented |
Method | ftp_ |
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_ |
Undocumented |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Undocumented |
Method | ftp_ |
File SIZE |
Method | ftp_ |
STORE (STOR) |
Method | ftp_ |
Undocumented |
Method | ftp_ |
Undocumented |
Method | ftp_ |
REPRESENTATION TYPE (TYPE) |
Method | ftp_ |
First part of login. Get the username the peer wants to authenticate as. |
Method | get |
Return a port for passive access, using self.passivePortRange attribute. |
Method | line |
Override this for when each line is received. |
Method | process |
Undocumented |
Method | reply |
Undocumented |
Method | send |
(Private) Encodes and sends a line |
Method | timeout |
Called when the connection times out. |
Method | type_ |
Undocumented |
Method | type_ |
Undocumented |
Method | type_ |
Undocumented |
Constant | FEATURES |
Undocumented |
Constant | PUBLIC |
Undocumented |
Class Variable | AUTHED |
Command channel was successfully authenticated. |
Class Variable | dtp |
Undocumented |
Class Variable | INAUTH |
Command channel is in the process of being authenticated. |
Class Variable | portal |
Undocumented |
Class Variable | RENAMING |
Command channel is between the renaming command sequence. |
Class Variable | UNAUTH |
Command channel is not yet authenticated. |
Instance Variable | binary |
The transfer mode. If false, ASCII. |
Instance Variable | disconnected |
Undocumented |
Instance Variable | dtp |
Generates a single DTP for this session |
Instance Variable | dtp |
Undocumented |
Instance Variable | dtp |
Port returned from listenTCP |
Instance Variable | listen |
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 |
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 |
Encode name to be sent over the wire. |
Method | _validate |
Validate the network protocol requested in an EPRT or EPSV command. |
Class Variable | _encoding |
Undocumented |
Instance Variable | _epsv |
If true, "EPSV ALL" was received from the client, requiring the server to reject all data connection setup commands other than EPSV. See RFC 2428. |
Instance Variable | _from |
Undocumented |
Instance Variable | _supported |
A collection of network protocol numbers supported by the EPRT and EPSV commands. |
Instance Variable | _user |
Undocumented |
Inherited from LineReceiver
:
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 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 LineReceiver
, Protocol
):
Method | make |
Make a connection to a transport and a server. |
Instance Variable | connected |
Undocumented |
Inherited from _PauseableMixin
(via LineReceiver
, Protocol
, BaseProtocol
):
Method | pause |
Undocumented |
Method | resume |
Undocumented |
Method | stop |
Undocumented |
Instance Variable | paused |
Undocumented |
Inherited from TimeoutMixin
(via LineReceiver
, Protocol
, BaseProtocol
, _PauseableMixin
):
Method | call |
Wrapper around reactor.callLater for test purpose. |
Method | reset |
Reset the timeout count down. |
Method | set |
Change the timeout period |
Instance Variable | time |
The number of seconds after which to timeout the connection. |
Method | __timed |
Undocumented |
Instance Variable | __timeout |
Undocumented |
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.Failure | Undocumented |
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.
Extended request for a data connection.
As described by RFC 2428 section 2:
The EPRT command allows for the specification of an extended address for the data connection. The extended address MUST consist of the network protocol as well as the network and transport addresses.
Extended request for a passive connection.
As described by RFC 2428 section 3:
The EPSV command requests that a server listen on a data port and wait for a connection. The EPSV command takes an optional argument. The response to this command includes only the TCP port number of the listening connection. The format of the response, however, is similar to the argument of the EPRT command. This allows the same parsing routines to be used for both commands. In addition, the format leaves a place holder for the network protocol and/or network address, which may be needed in the EPSV response in the future.
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.
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
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:str | The path for which a directory listing should be returned. |
Returns | |
Deferred | a Deferred which will be fired when the listing request is finished. |
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.
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:str | The path to the file which should be transferred over the data transfer channel. |
Returns | |
Deferred | a Deferred which will be fired when the transfer is done. |
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
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.
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).
Return a port for passive access, using self.passivePortRange attribute.
Parameters | |
factory:twisted.internet.protocol.ServerFactory | the protocol factory to connect to the port. |
interface:str | the local IPv4 or IPv6 address to which to bind; defaults to "", i.e. all IPv4 addresses. |
Override this for when each line is received.
Parameters | |
line:bytes | The line which was received with the delimiter removed. |
Called when the connection times out.
Override to define behavior other than dropping the connection.
A callable with the signature of twisted.internet.interfaces.IReactorTCP.listenTCP
which will be used to create Ports for passive connections (mainly for testing).
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 unicode | Name to be encoded. |
Returns | |
bytes | Wire format of name. |
Validate the network protocol requested in an EPRT or EPSV command.
For now we just hardcode the protocols we support, since this layer doesn't have a good way to discover that.
Parameters | |
protocol:str | An address family number. See RFC 2428 section 2. |
Raises | |
FTPCmdError | If validation fails. |
If true, "EPSV ALL" was received from the client, requiring the server to reject all data connection setup commands other than EPSV. See RFC 2428.