如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#!/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)
|
以上这篇Python通过paramiko远程下载Linux服务器上的文件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/ChristopherChen/article/details/54646135