\#!/usr/local/bin/python
\# encoding:utf-8

import paramiko
import 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)

原文:https://blog.csdn.net/christopherchen/article/details/54646135

标签: Linux, path, Python, PATH, LOCAL, REMOTE, FILENAME, paramiko

相关文章推荐

添加新评论,含*的栏目为必填