mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
File transfer method improvements
This commit is contained in:
parent
c24fb75eee
commit
e0800d0ac1
1 changed files with 9 additions and 6 deletions
|
@ -53,25 +53,28 @@ class Ssh(object):
|
||||||
self.logger.error('A problem occurred while sending file. Exception message: {0}'.format(str(e)))
|
self.logger.error('A problem occurred while sending file. Exception message: {0}'.format(str(e)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_file(self, local_path=None):
|
def get_file(self, local_path=None, file_name=None):
|
||||||
self.logger.debug('Getting file ...')
|
self.logger.debug('Getting file ...')
|
||||||
file_md5 = None
|
|
||||||
try:
|
try:
|
||||||
tmp_file_name = str(Util.generate_uuid())
|
tmp_file_name = str(Util.generate_uuid())
|
||||||
local_full_path = System.Ahenk.received_dir_path() + tmp_file_name
|
local_full_path = System.Ahenk.received_dir_path() + tmp_file_name
|
||||||
sftp = paramiko.SFTPClient.from_transport(self.connection)
|
sftp = paramiko.SFTPClient.from_transport(self.connection)
|
||||||
sftp.get(self.target_path, local_full_path)
|
sftp.get(self.target_path, local_full_path)
|
||||||
file_md5 = str(Util.get_md5_file(local_full_path))
|
|
||||||
if local_path is None:
|
if local_path is None:
|
||||||
receive_path = System.Ahenk.received_dir_path()
|
receive_path = System.Ahenk.received_dir_path()
|
||||||
else:
|
else:
|
||||||
receive_path = local_path
|
receive_path = local_path
|
||||||
Util.rename_file(local_full_path, receive_path + file_md5)
|
if file_name is not None:
|
||||||
self.logger.debug('File was downloaded to {0} from {1}'.format(local_full_path, self.target_path))
|
f_name = file_name
|
||||||
|
else:
|
||||||
|
f_name = str(Util.get_md5_file(local_full_path))
|
||||||
|
Util.rename_file(local_full_path, receive_path + f_name)
|
||||||
|
self.logger.debug('File was downloaded to {0} from {1}'.format(receive_path, self.target_path))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.warning('A problem occurred while downloading file. Exception message: {0}'.format(str(e)))
|
self.logger.warning('A problem occurred while downloading file. Exception message: {0}'.format(str(e)))
|
||||||
raise
|
raise
|
||||||
return file_md5
|
return f_name
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.logger.debug('Connecting to {0} via {1}'.format(self.target_hostname, self.target_port))
|
self.logger.debug('Connecting to {0} via {1}'.format(self.target_hostname, self.target_port))
|
||||||
|
|
Loading…
Reference in a new issue