def transfer_file(hostname_, port_, username_, password_, fdir_, fname_):
try:
print('Establishing SSH connection to:', hostname_, port_, '...')
t = paramiko.Transport((hostname_, port_))
t.start_client()
if not t.is_authenticated():
print('Trying password login...')
t.auth_password(username=username_, password=password_)
sftp = paramiko.SFTPClient.from_transport(t)
local_file = os.path.join(fdir_, fname_)
remote_file = DIR_REMOTE + '/' + fname_
try:
print('start transport...')
sftp.put(local_file, remote_file)
except:
LOG.error('error...')
raise
t.close()
LOG.info('??????????zip??...')
os.remove(local_file)
except Exception as e:
print(e)
try:
LOG.info('end transport and close it...')
t.close()
except:
pass
评论列表
文章目录