diff --git a/agent/transport/server.py b/agent/control/remote.py similarity index 89% rename from agent/transport/server.py rename to agent/control/remote.py index f1543ba..9a9296c 100644 --- a/agent/transport/server.py +++ b/agent/control/remote.py @@ -17,8 +17,8 @@ # """ -Providing access for remote cybertools.agent instances by listening -for requests from client agents. +Providing access for remote agent instances by listening for requests +from remote transport agents. $Id$ """ diff --git a/agent/transport/file/sftp.py b/agent/transport/file/sftp.py index cd07aa6..ebb3acb 100644 --- a/agent/transport/file/sftp.py +++ b/agent/transport/file/sftp.py @@ -17,18 +17,18 @@ # """ -Transferring files to a remote site via SCP. +Transferring files to a remote site via SFTP. $Id$ """ -from twisted.conch.ssh import connection +from twisted.conch.ssh import channel, common, connection from twisted.conch.ssh import filetransfer, transport, userauth from twisted.internet import defer, protocol, reactor -class FileTransferConnection(protocol.ClientFactory): - """ Transfers files to a remote SCP server. +class FileTransfer(protocol.ClientFactory): + """ Transfers files to a remote SCP/SFTP server. """ def __init__(self, host, port, username, password): @@ -38,60 +38,77 @@ class FileTransferConnection(protocol.ClientFactory): reactor.connectTCP(host, port, self) def buildProtocol(self, addr): - protocol = self.protocol = ClientTransport(self.username, self.password) + protocol = self.protocol = ClientTransport(self) return protocol def copyToRemote(self, localPath, remotePath): """ Copies a file, returning a deferred. """ d = defer.Deferred() - self.queue.append((localPath, remotePath, d)) - #d = self.protocol.openFile('text.txt', filetransfer.FXF_WRITE, {}) - #d.addCallback(self.write) + self.queue.append(dict(deferred=d, + command='copyToRemote', + localPath=localPath, + remotePath=remotePath)) return d - def write(self, file): - file.writeChunk(0, 'hello') - file.close() - return 'Done' - def close(self): + # TODO: put in queue... self.protocol.transport.loseConnection() print 'connection closed' class ClientTransport(transport.SSHClientTransport): - def __init__(self, username, password): - self.username = username - self.password = password + def __init__(self, factory): + self.factory = factory def verifyHostKey(self, pubKey, fingerprint): # this is insecure!!! return defer.succeed(True) def connectionSecure(self): - self.requestService(UserAuth(self.username, self.password, - ClientConnection())) + self.requestService(UserAuth(self.factory, ClientConnection(self.factory))) class ClientConnection(connection.SSHConnection): + def __init__(self, factory): + connection.SSHConnection.__init__(self) + self.factory = factory + def serviceStarted(self): self.openChannel(SFTPChannel(conn=self)) class SFTPChannel(channel.SSHChannel): + name = 'session' + + def channelOpen(self, data): + d = self.conn.sendRequest(self, 'subsystem', common.NS('sftp'), wantReply=1) + d.addCallback(self.channelOpened) + def channelOpened(self, data): - self.client = filetransfer.FileTransferClient + print 'channelOpened', data + self.client = filetransfer.FileTransferClient() + self.client.makeConnection(self) + self.dataReceived = self.client.dataReceived + self.execute() + + def execute(self): + queue = self.conn.factory.queue + print 'execute, queue =', queue + + def copyToRemote(self, params): + remotePath = params['remotePath'] + d = self.protocol.openFile(remotePath, filetransfer.FXF_WRITE, {}) class UserAuth(userauth.SSHUserAuthClient): - def __init__(self, user, password, connection): - userauth.SSHUserAuthClient.__init__(self, user, connection) - self.password = password + def __init__(self, factory, connection): + userauth.SSHUserAuthClient.__init__(self, factory.username, connection) + self.password = factory.password def getPassword(self, prompt=None): return defer.succeed(self.password) diff --git a/agent/transport/local.py b/agent/transport/loops.py similarity index 87% rename from agent/transport/local.py rename to agent/transport/loops.py index 9807cb2..df2b2b1 100644 --- a/agent/transport/local.py +++ b/agent/transport/loops.py @@ -17,8 +17,7 @@ # """ -Transferring information to an application on the same machine, typically -a loops site on a local Zope instance. +Transferring information to a loops site on a local Zope instance. $Id$ """ diff --git a/agent/transport/client.py b/agent/transport/remote.py similarity index 87% rename from agent/transport/client.py rename to agent/transport/remote.py index 7e80728..3935f19 100644 --- a/agent/transport/client.py +++ b/agent/transport/remote.py @@ -18,7 +18,8 @@ """ Transferring information to or requesting information from a remote -cybertools.agent instance with a corresponding server agent. +cybertools.agent instance by transferring files to the remote system +and sending requests to a corresponding remote controller. $Id$ """