[Twisted-Python] Problem with ftp upload

Thomas Jacob jacob at internet24.de
Fri Nov 3 04:32:52 EST 2006


There is bug in storeFile's Consumer interface
(Cf.  report + patch http://twistedmatrix.com/trac/ticket/1794 )

As for disconnecting, why not call ftpClient->quit() after
your upload has finished?

On Thu, 2006-11-02 at 20:57 +0000, Stéphane Brault wrote:
> Hi,
> 
> I'm using twisted ftp api to upload files, I also added the ticket 1914 patch.
> Here is my code :
> class myFTP(object):
>     
>     def __init__(self, login, password):
>         self.creator = ClientCreator(reactor, FTPClient, login, password, passive=0)
>         
> 
>     def connectionFailed(self, f):
>         print 'connection error'
> 
> 
>     def success(self, response):
>         print 'Success'
> 
> 
>     def fail(self, error):
>         print 'Erreur:' + error
> 
> 
>     def doOperation(self, operation, data):
>         d = self.creator.connectTCP(FTP_ADDRESS, 21)
>         if operation == 'addItems':
>             return d.addCallback(self.inventoryUpload, data).addErrback(self.connectionFailed)
>         elif ....
>         
>         
>         
>     def _upload(self, consumer, file):
>         return FileSender().beginFileTransfer(file, consumer).addCallback(lambda _: consumer.finish()).addCallback(lambda _: file.close())
>     
>     
>     def inventoryUpload(self, ftpClient, file):
>         name = '/stock/entrees/export_items_' + encodeDate(datetime.datetime.now()) + '.txt'
>         return ftpClient.storeFile(name)[0].addCallback(self._upload, file).addCallbacks(self.success, self.fail)
>         
>     ....
> 
> The operation is called this way:
> call = myFTP(login, password)
> call.doOperation('addItems', StringIO(data))
> 
> The file is created but empty, it seems that _upload is not called, I can't understand why, any hint ?
> I was also wondering how to disconnect once my work is done, I don't think keeping open connections is a good thing.
> 
> Thanks,
> 
> Stéphane
> 
> 
> 
> 
> 	
> 
> 	
> 		
> ___________________________________________________________________________ 
> Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
> Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses 
> http://fr.answers.yahoo.com
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20061103/4a49e344/attachment.pgp 


More information about the Twisted-Python mailing list