def _connection_pwd(self):
try:
self.connection = paramiko.Transport((config.server[self.server_name]['hostname'],
config.server[self.server_name]['port']))
self.connection.connect(username=config.server[self.server_name]['username'],
password=config.server[self.server_name]['password'])
except Exception as e:
raise e
def _connection_key(self):
try:
self.connection = paramiko.Transport((config.server[self.server_name]['hostname'],
config.server[self.server_name]['port']))
sftp_key = paramiko.RSAKey.from_private_key_file(config.server[self.server_name]['key'])
self.connection.connect(username=config.server[self.server_name]['username'],
pkey=sftp_key)
except Exception as e:
raise e
def transport_file(self, local_path, file_path):
sftp = paramiko.SFTPClient.from_transport(self.connection)
sftp.put(local_path, file_path, self._print_total)
sftp.close()
def _print_total(self, trans_ferred, toBeTrans_ferred):
print("Transferred: {0}\tOut of: {1}".format(trans_ferred, toBeTrans_ferred))