[Twisted-Python] FTPClient - aborting transfers

Matt Bennett matt at bennett.name
Tue Sep 1 18:51:21 EDT 2009


Hello all,

I've got an FTPClient implementation very similar to the one at [1],
and I've added the ability to retrieve a file from the server with the
following snippet:

class FileReceiver(Protocol):
    """
        Protocol subclass that writes received data to a local file.
    """
    def __init__(self, filename):
        self.file = open(filename, 'wb')

    def dataReceived(self, data):
        self.file.write(data)

receiver = FileReceiver(local_path)
d = ftpClient.retrieveFile(remote_path,receiver)

I want to be able to abort the transfers if they've not completed
after a specific period of time. When the timeout is triggered, I call
ftpClient.transport.loseConnection() which seems to stop the dL on
line 109 of [1] from firing, but the data transfer continues until
completion. This is true for both storing and retrieving files.

In the storing case, I thought that
twisted.protocols.basic.FileSender's stopProducing method might help,
but all it seems to do is trigger the errback for anyone waiting for a
response - the actual data transfer continues.

How do I abort the transfer and clear the wire when the timeout fires?

Many thanks,
Matt.


[1] http://twistedmatrix.com/pipermail/twisted-python/attachments/20031204/d43a4251/attachment.txt



More information about the Twisted-Python mailing list