[Twisted-Python] FTPClient storeFile help.

Jp Calderone exarkun at intarweb.us
Fri Oct 3 12:59:23 EDT 2003


On Fri, Oct 03, 2003 at 11:18:28AM +0100, Oisin Mulvihill wrote:
> Hi,
> 
> [snip]
> Why are there two deferred objects returned by storeFile? The documentation
> says:
> 
> storeFile (self ,path ):
> 
>    Store a file at the given path.
> 
>    This method issues the 'STOR' FTP command.
> 
>    Returns:
> 
>    A 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.
> 
> This really doesn't help me much. I get the impression that storeFile
> isn't sending the contents of file, because its waiting for me to stream
> the file contents somehow. Maybe via IFinishableConsumer?

  Correct, I believe.  It looks like you can use FileSender (from t.p.basic)
if you're just sending something off disk (or from any file object, really)
here.

> 
> In my current program, using ftplib, I do the following to upload a file:
> 
>    :
>    ftp.storbinary('STOR %s' % (filename), fp)
>    :
> 
> This has the filename and a file descriptor passed to it. Is something
> like this needed with storeFile?
> 
> Please can someone give me an answer to this, as looking at the code for
> twisted.protocols.ftp isn't helping much either. This function seems to be
> a mystery to me and I want to understand how to use it properly.
> 

  Try...

    from twisted.protocols.basic import FileSender

    def sendfile(consumer, fileObj):
        s = FileSender()
        return s.beginFileTransfer(fileObj, consumer
            ).addCallback(lambda _: consumer.finish()
            )

    dC, dL = p.storeFile("path")
    dC.addCallback(sendfile, fileObj)

  Jp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031003/34d2abe8/attachment.pgp 


More information about the Twisted-Python mailing list