file transfer via ssh

This commit is contained in:
Volkan Şahin 2016-05-06 16:35:45 +03:00
parent a8d8aafd46
commit a2676abea4

View file

@ -25,11 +25,10 @@ class FileTransfer(slixmpp.ClientXMPP):
self.my_jid = str(self.configuration_manager.get('CONNECTION', 'uid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/sender') self.my_jid = str(self.configuration_manager.get('CONNECTION', 'uid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/sender')
self.my_pass = str(self.configuration_manager.get('CONNECTION', 'password')) self.my_pass = str(self.configuration_manager.get('CONNECTION', 'password'))
self.receiver = self.configuration_manager.get('CONNECTION', 'receiverjid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/Smack' self.receiver = self.configuration_manager.get('CONNECTION', 'receiverjid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/Smack'
self.logger.debug('[FileTransfer] File transfer client was configured.')
try: slixmpp.ClientXMPP.__init__(self, self.my_jid, self.my_pass)
slixmpp.ClientXMPP.__init__(self, self.my_jid, self.my_pass) self.logger.debug('[FileTransfer] XMPP Client was created for file transfer.')
except Exception as e:
print(str(e))
self.register_plugin('xep_0030') # Service Discovery self.register_plugin('xep_0030') # Service Discovery
self.register_plugin('xep_0065') self.register_plugin('xep_0065')
@ -38,7 +37,7 @@ class FileTransfer(slixmpp.ClientXMPP):
@asyncio.coroutine @asyncio.coroutine
def start(self, event): def start(self, event):
print('sending...') self.logger.debug('[FileTransfer] Sending file ...')
try: try:
# Open the S5B stream in which to write to. # Open the S5B stream in which to write to.
@ -49,7 +48,7 @@ class FileTransfer(slixmpp.ClientXMPP):
while True: while True:
data = self.file.read(1000) data = self.file.read(1000)
i += 1 i += 1
print('-->'+str(i)+'--'+str(len(data))) print('-->' + str(i) + '--' + str(len(data)))
if not data: if not data:
break break
yield from proxy.write(data) yield from proxy.write(data)
@ -59,12 +58,14 @@ class FileTransfer(slixmpp.ClientXMPP):
proxy.transport.write_eof() proxy.transport.write_eof()
except Exception as e: except Exception as e:
print('File transfer errored:' + str(e)) self.logger.debug('[FileTransfer] A problem occurred while file transferring. Error Message: {}'.format(str(e)))
else: else:
print('File transfer finished') self.logger.debug('[FileTransfer] File transfer is finished.')
finally: finally:
self.logger.debug('[FileTransfer] Disconnecting file transfer resource.')
self.disconnect() self.disconnect()
self.file.close() self.file.close()
self.logger.debug('[FileTransfer] Disconnected file transfer resource.')
@staticmethod @staticmethod
def run(file_path): def run(file_path):