代码:
import paramiko
client = paramiko.SSHClient()
try:
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host_ip, port, username, password, timeout=5)
sftp_client = client.open_sftp()
remote_file = sftp_client.open(file_path, 'r+')
'''
your code to operate the remote file
'''
remote_file.close()
except:
print('failed to open the remote file!')
finally:
client.close()