天天看点

python 使用paramiko模块访问远程文件

代码:

import paramiko

client = paramiko.SSHClient()
try:
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(host_ip, port, username, password, timeout=)
    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()