首页 > 代码库 > 转python批量上传的初版

转python批量上传的初版

转自:http://world77.blog.51cto.com/blog/414605/707008

#!/usr/bin/env python 
import paramiko 
import os 
import datetime
ipfile=ip.txt
#hostname=74.63.229.* 
username=root 
password=redhat 
port=22
ipfile = open(ip.txt,r) 
local_dir=/home/test 
remote_dir=/home/test/123
for file in ipfile.readlines():
    t=paramiko.Transport((file,port)) 
    t.connect(username=username,password=password) 
    sftp=paramiko.SFTPClient.from_transport(t) 
    
    files=os.listdir(local_dir) 
    for f in files: 
        print ‘‘ 
        print ######################################### 
        print Beginning to upload file %s  % datetime.datetime.now() 
        print Uploading file:,os.path.join(local_dir,f) 
    
    
        sftp.put(os.path.join(local_dir,f),os.path.join(remote_dir,f)) 
    
        print Upload file success %s  % datetime.datetime.now() 
        print ‘‘ 
        print ########################################## 
    
    
    t.close() 

 

转python批量上传的初版