1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
class SFTPUtils():
def __init__(self, sftp_name, sftp_conf):
try:
self.conn = pysftp.Connection(host = sftp_conf['host'],
username = sftp_conf['user'],
private_key = sftp_conf['private_key'],
password = sftp_conf['pass'],
port = sftp_conf['port'],
private_key_pass = sftp_conf['private_key_pass'])
except Exception as e:
self.conn = None
logger.error('Could not connect to {}'.format(sftp_name))
logger.debug(e)
raise e
def upload_file(self, local_path, remote_path):
logger.debug('upload_file method...')
logger.debug('dumping conn_info:')
logger.debug(self.conn)
try :
self.conn.put(local_path, remote_path)
except TimeoutError:
logger.error('Cant connect to FTP')
return False
logger.info('User uploaded file %s' % (local_path))
return True |
Partager