class documentation

class twisted.protocols.ftp.FTPClient(FTPClientBasic): (source)

View In Hierarchy

FTPClient is a client implementation of the FTP protocol which exposes FTP commands as methods which return Deferreds.

Each command method returns a Deferred which is called back when a successful response code (2xx or 3xx) is received from the server or which is error backed if an error response code (4xx or 5xx) is received from the server or if a protocol violation occurs. If an error response code is received, the Deferred fires with a Failure wrapping a CommandFailed instance. The CommandFailed instance is created with a list of the response lines received from the server.

See RFC 959 for error code definitions.

Both active and passive transfers are supported.

Instance Variable passive See description in __init__.
Method __init__ Constructor.
Method fail Disconnect, and also give an error to any queued deferreds.
Method receiveFromConnection Retrieves a file or listing generated by the given command, feeding it to the given protocol.
Method queueLogin Login: send the username, send the password, and set retrieval mode to binary
Method sendToConnection XXX
Method generatePortCommand (Private) Generates the text of a given PORT command.
Method escapePath Returns a FTP escaped path (replace newlines with nulls).
Method retrieveFile Retrieve a file from the given path
Method storeFile Store a file at the given path.
Method rename Rename a file.
Method list Retrieve a file listing into the given protocol instance.
Method nlst Retrieve a short file listing into the given protocol instance.
Method cwd Issues the CWD (Change Working Directory) command.
Method makeDirectory Make a directory
Method removeFile Delete a file on the server.
Method removeDirectory Delete a directory on the server.
Method cdup Issues the CDUP (Change Directory UP) command.
Method pwd Issues the PWD (Print Working Directory) command.
Method getDirectory Returns the current remote directory.
Method quit Issues the QUIT command.
Method _openDataConnection This method returns a DeferredList.

Inherited from FTPClientBasic:

Class Variable debug Undocumented
Instance Variable actionQueue Undocumented
Instance Variable greeting Undocumented
Instance Variable nextDeferred Undocumented
Instance Variable response Undocumented
Method sendLine Sends a line, unless line is None.
Method sendNextCommand (Private) Processes the next command in the queue.
Method queueCommand Add an FTPCommand object to the queue.
Method queueStringCommand Queues a string to be issued as an FTP command
Method popCommandQueue Return the front element of the command queue, or None if empty.
Method lineReceived (Private) Parses the response messages from the FTP server.
Method connectionLost Called when the connection is shut down.
Class Variable _encoding Undocumented
Instance Variable _failed Undocumented
Method _fail Errback all queued deferreds.
Method _cb_greeting Undocumented

Inherited from LineReceiver (via FTPClientBasic):

Class Variable delimiter The line-ending delimiter to use. By default this is b'\r\n'.
Class Variable 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.
Instance Variable line_mode Undocumented
Method clearLineBuffer Clear buffered data.
Method dataReceived Protocol.dataReceived. Translates bytes into lines, and calls lineReceived (or rawDataReceived, depending on mode.)
Method setLineMode Sets the line-mode of this receiver.
Method setRawMode Sets the raw mode of this receiver. Further data received will be sent to rawDataReceived rather than lineReceived.
Method rawDataReceived Override this for when raw data is received.
Method lineLengthExceeded Called when the maximum line length has been reached. Override if it needs to be dealt with in some special way.
Instance Variable _buffer Undocumented
Instance Variable _busyReceiving Undocumented

Inherited from Protocol (via FTPClientBasic, LineReceiver):

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

Inherited from BaseProtocol (via FTPClientBasic, LineReceiver, Protocol):

Instance Variable connected Undocumented
Instance Variable transport Undocumented
Method makeConnection Make a connection to a transport and a server.
Method connectionMade Called when a connection is made.

Inherited from _PauseableMixin (via FTPClientBasic, LineReceiver):

Instance Variable paused Undocumented
Method pauseProducing Undocumented
Method resumeProducing Undocumented
Method stopProducing Undocumented
passive = (source)
See description in __init__.
def __init__(self, username='anonymous', password='twisted@twistedmatrix.com', passive=1): (source)

Constructor.

I will login as soon as I receive the welcome message from the server.

ParametersusernameFTP username
passwordFTP password
passiveflag that controls if I use active or passive data connections. You can also change this after construction by assigning to self.passive.
def fail(self, error): (source)

Disconnect, and also give an error to any queued deferreds.

def receiveFromConnection(self, commands, protocol): (source)

Retrieves a file or listing generated by the given command, feeding it to the given protocol.

Parameterscommandslist of strings of FTP commands to execute then receive the results of (e.g. LIST, RETR)
protocolA Protocol instance e.g. an FTPFileListProtocol, or something that can be adapted to one. Typically this will be an IConsumer implementation.
ReturnsDeferred.
def queueLogin(self, username, password): (source)

Login: send the username, send the password, and set retrieval mode to binary

def sendToConnection(self, commands): (source)

XXX

ReturnsA tuple of two Deferreds:
  • Deferred IFinishableConsumer. You must call the finish method on the IFinishableConsumer when the file is completely transferred.
  • Deferred list of control-connection responses.
def _openDataConnection(self, commands, protocol): (source)

This method returns a DeferredList.

def generatePortCommand(self, portCmd): (source)

(Private) Generates the text of a given PORT command.

def escapePath(self, path): (source)

Returns a FTP escaped path (replace newlines with nulls).

def retrieveFile(self, path, protocol, offset=0): (source)

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.

Parameterspathpath to file that you wish to receive.
protocola Protocol instance.
offsetoffset to start downloading from
ReturnsDeferred
def storeFile(self, path, offset=0): (source)

Store a file at the given path.

This method issues the 'STOR' FTP command.

ReturnsA tuple of two Deferreds:
  • Deferred IFinishableConsumer. You must call the finish method on the IFinishableConsumer when the file is completely transferred.
  • Deferred list of control-connection responses.
def rename(self, pathFrom, pathTo): (source)

Rename a file.

This method issues the RNFR/RNTO command sequence to rename pathFrom to pathTo.

ParameterspathFromthe absolute path to the file to be renamed (type: str)
pathTothe absolute path to rename the file to. (type: str)
ReturnsA Deferred which fires when the rename operation has succeeded or failed. If it succeeds, the Deferred is called back with a two-tuple of lists. The first list contains the responses to the RNFR command. The second list contains the responses to the RNTO command. If either RNFR or RNTO fails, the Deferred is errbacked with CommandFailed or BadResponse. (type: Deferred)
Present Since8.2
def list(self, path, protocol): (source)

Retrieve a file listing into the given protocol instance.

This method issues the 'LIST' FTP command.

Parameterspathpath to get a file listing for.
protocola Protocol instance, probably a FTPFileListProtocol instance. It can cope with most common file listing formats.
ReturnsDeferred
def nlst(self, path, protocol): (source)

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.

Parameterspathpath to get short file listing for.
protocola Protocol instance.
def cwd(self, path): (source)

Issues the CWD (Change Working Directory) command.

Returnsa Deferred that will be called when done.
def makeDirectory(self, path): (source)

Make a directory

This method issues the MKD command.

ParameterspathThe path to the directory to create. (type: str)
ReturnsA Deferred which fires when the server responds. If the directory is created, the Deferred is called back with the server response. If the server response indicates the directory was not created, the Deferred is errbacked with a Failure wrapping CommandFailed or BadResponse. (type: Deferred)
Present Since8.2
def removeFile(self, path): (source)

Delete a file on the server.

removeFile issues a DELE command to the server to remove the indicated file. Note that this command cannot remove a directory.

ParameterspathThe path to the file to delete. May be relative to the current dir. (type: str)
ReturnsA Deferred which fires when the server responds. On error, it is errbacked with either CommandFailed or BadResponse. On success, it is called back with a list of response lines. (type: Deferred)
Present Since8.2
def removeDirectory(self, path): (source)

Delete a directory on the server.

removeDirectory issues a RMD command to the server to remove the indicated directory. Described in RFC959.

ParameterspathThe path to the directory to delete. May be relative to the current working directory. (type: str)
ReturnsA Deferred which fires when the server responds. On error, it is errbacked with either CommandFailed or BadResponse. On success, it is called back with a list of response lines. (type: Deferred)
Present Since11.1
def cdup(self): (source)

Issues the CDUP (Change Directory UP) command.

Returnsa Deferred that will be called when done.
def pwd(self): (source)

Issues the PWD (Print Working Directory) command.

The getDirectory does the same job but automatically parses the result.

Returnsa 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.
def getDirectory(self): (source)

Returns the current remote directory.

Returnsa Deferred that will be called back with a str giving the remote directory or which will errback with CommandFailed if an error response is returned.
def quit(self): (source)

Issues the QUIT command.

ReturnsA Deferred that fires when the server acknowledges the QUIT command. The transport should not be disconnected until this Deferred fires.
API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.