From 6e0ef6fd03ad7dfd2daff903fc8e66db58b49ea3 Mon Sep 17 00:00:00 2001 From: helmutm Date: Wed, 4 Jun 2008 15:45:55 +0000 Subject: [PATCH] work in progress: SFTP transfer git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2664 fd906abe-77d9-0310-91a1-e0d9ade77398 --- agent/transport/file/sftp.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/agent/transport/file/sftp.py b/agent/transport/file/sftp.py index bf3586f..174d420 100644 --- a/agent/transport/file/sftp.py +++ b/agent/transport/file/sftp.py @@ -31,6 +31,8 @@ class FileTransfer(protocol.ClientFactory): """ Transfers files to a remote SCP/SFTP server. """ + channel = None + def __init__(self, host, port, username, password): self.username = username self.password = password @@ -51,6 +53,9 @@ class FileTransfer(protocol.ClientFactory): command='upload', localPath=localPath, remotePath=remotePath)) + if len(self.queue) == 1 and self.channel is not None: + # the channel has emptied the queue + self.channel.execute() return d def close(self): @@ -75,14 +80,33 @@ class SFTPChannel(channel.SSHChannel): self.client.makeConnection(self) self.dataReceived = self.client.dataReceived self.execute() + self.conn.factory.channel = self def execute(self): queue = self.conn.factory.queue - print 'execute, queue =', queue + if queue: + command = queue.pop() + commandName = command.pop('command') + method = getattr(self, 'command_' + commandName, None) + if method is not None: + self.params = command + method() - def upload(self, params): + def command_upload(self): + params = self.params remotePath = params['remotePath'] - d = self.protocol.openFile(remotePath, filetransfer.FXF_WRITE, {}) + d = self.client.openFile(remotePath, + filetransfer.FXF_WRITE | filetransfer.FXF_CREAT, {}) + print 'command_upload', params + d.addCallbacks(self.writeChunk, self.logError) + + def writeChunk(self, clientFile): + print 'writeChunk', clientFile + params = self.params + d = clientFile.writeChunk(0, 'Hello World') + + def logError(self, reason): + print 'error', reason # classes for managing the SSH protocol and connection