【python】paramiko+sftp远程下载文件


#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
#add by tanglin@2012.6.14

import os
import re
import paramiko
import time
def sftp_down_f(server_path,local_path):  
    t=paramiko.Transport(('172.17.242.82',22))
    t.connect(username='root',password='Macro3')
    sftp=paramiko.SFTPClient.from_transport(t)
    sftp.get(server_path,local_path)
  
while True:
    
    sftp_down_f("/var/log/messages","D:\messages")
    time.sleep(2)
  

                 

上传文件:sftp.put(local_path,server_path)

 
原文地址:https://www.cnblogs.com/bashaowei/p/8761500.html