如下所示:
#!/usr/local/bin/python# encoding:utf-8 import paramikoimport os HOST_IP='59.110.12.72'REMOTE_PATH='/proc'REMOTE_FILENAME='meminfo'LOCAL_PATH='./proc'USERNAME='niu'PASSWORD='123456' def remote_scp(host_ip,remote_path,local_path,file_name,username,password): t = paramiko.Transport((host_ip,22)) t.connect(username=username, password=password) # 登录远程服务器 sftp = paramiko.SFTPClient.from_transport(t) # sftp传输协议 src = remote_path+'/'+file_name des = local_path+'/'+file_name sftp.get(src,des) t.close() if not os.path.isdir(LOCAL_PATH): os.makedirs(LOCAL_PATH)if not os.path.isfile(LOCAL_PATH+'/'+REMOTE_FILENAME): fp=open(LOCAL_PATH+'/'+REMOTE_FILENAME,'w') fp.close() remote_scp(HOST_IP,REMOTE_PATH,LOCAL_PATH,REMOTE_FILENAME,USERNAME,PASSWORD)
以上这篇Python通过paramiko远程下载Linux服务器上的文件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网之家。
新闻热点
疑难解答