work in progress: SFTP transfer
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2664 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
018beff4a5
commit
6e0ef6fd03
1 changed files with 27 additions and 3 deletions
|
@ -31,6 +31,8 @@ class FileTransfer(protocol.ClientFactory):
|
||||||
""" Transfers files to a remote SCP/SFTP server.
|
""" Transfers files to a remote SCP/SFTP server.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
channel = None
|
||||||
|
|
||||||
def __init__(self, host, port, username, password):
|
def __init__(self, host, port, username, password):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
@ -51,6 +53,9 @@ class FileTransfer(protocol.ClientFactory):
|
||||||
command='upload',
|
command='upload',
|
||||||
localPath=localPath,
|
localPath=localPath,
|
||||||
remotePath=remotePath))
|
remotePath=remotePath))
|
||||||
|
if len(self.queue) == 1 and self.channel is not None:
|
||||||
|
# the channel has emptied the queue
|
||||||
|
self.channel.execute()
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
@ -75,14 +80,33 @@ class SFTPChannel(channel.SSHChannel):
|
||||||
self.client.makeConnection(self)
|
self.client.makeConnection(self)
|
||||||
self.dataReceived = self.client.dataReceived
|
self.dataReceived = self.client.dataReceived
|
||||||
self.execute()
|
self.execute()
|
||||||
|
self.conn.factory.channel = self
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
queue = self.conn.factory.queue
|
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']
|
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
|
# classes for managing the SSH protocol and connection
|
||||||
|
|
Loading…
Add table
Reference in a new issue