[Twisted-Python] Problem with ftp upload
Stéphane Brault
stephane_brault at yahoo.fr
Thu Nov 2 13:57:00 MST 2006
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
More information about the Twisted-Python
mailing list