[Twisted-Python] FTP Client - questions

Andrew Bennetts andrew at bemusement.org
Thu Mar 18 18:52:30 EDT 2010


Renan Mathias Fernandes wrote:
> Hello,
> 
> 	I am trying to learn/implement a FTP Client, but I am facing a problem:
> 	How can I check if the retrieveFile method has finished downloading a
> 	file? As far as I can see, there is no easy way to do this, am I
> 	incorrect?

You are incorrect.  FTPClient.retrieveFile returns a Deferred that fires
when the download is complete (or reports a failure).

The API doc hints at this, but could be clearer.
<http://twistedmatrix.com/documents/current/api/twisted.protocols.ftp.FTPClient.html#retrieveFile>

>     try:
>         ftpClient.retrieveFile('testFile.txt',test)
>     except:
>         print "Exception -", sys.exc_value
>         reactor.stop()
> 
> 
> Can anyone shed a light?

A direct correction to this snippet is:

    d = ftpClient.retrieveFile('testFile.txt', test)
    def eb(failure):
    	print "Exception -", failure.getErrorMessage()
	reactor.stop()
    d.addErrback(eb)

(Although like your code will only stop the reactor when an error
occurs, and doesn't do anything when the download completes
successfully.)

-Andrew.




More information about the Twisted-Python mailing list