work in progress: resource/file transfer with SFTP

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2653 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-05-31 08:58:13 +00:00
parent d319203a4f
commit 757d47ba12

View file

@ -41,12 +41,14 @@ class FileTransfer(protocol.ClientFactory):
protocol = self.protocol = ClientTransport(self)
return protocol
def copyToRemote(self, localPath, remotePath):
def upload(self, localPath, remotePath):
""" Copies a file, returning a deferred.
"""
d = defer.Deferred()
# we put everything in a queue so that more than one file may
# be transferred in one connection.
self.queue.append(dict(deferred=d,
command='copyToRemote',
command='upload',
localPath=localPath,
remotePath=remotePath))
return d
@ -57,6 +59,34 @@ class FileTransfer(protocol.ClientFactory):
print 'connection closed'
class SFTPChannel(channel.SSHChannel):
""" An SSH channel using the SFTP subsystem for transferring files
and issuing other filesystem requests.
"""
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()
self.client.makeConnection(self)
self.dataReceived = self.client.dataReceived
self.execute()
def execute(self):
queue = self.conn.factory.queue
print 'execute, queue =', queue
def upload(self, params):
remotePath = params['remotePath']
d = self.protocol.openFile(remotePath, filetransfer.FXF_WRITE, {})
# classes for managing the SSH protocol and connection
class ClientTransport(transport.SSHClientTransport):
def __init__(self, factory):
@ -80,30 +110,6 @@ class ClientConnection(connection.SSHConnection):
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):
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, factory, connection):