Python uploads different file names to different servers

Source: Internet
Author: User

#!/usr/bin/python  #-*- coding: utf-8 -*-  import paramiko   Import datetime  import os,tab,sysfrom multiprocessing import process,  Poolhost_list =  (' 192.168.1.127 ', ' root ', ' 123456 '), (' 192.168.1.143 ', ' root ', ' 123456 '), (' 192.168.1.141 ', ' root ', ' 123456 '), Def put (host_info,local_dir, remote_dir): Try:ip,username,password  = host_infot = paramiko. Transport ((ip, 22))   t.connect (Username=username, password=password)   sftp  = paramiko. Sftpclient.from_transport (t) files = os.listdir (Local_dir) A=host_info[0].split (".") [-1] #取出ip的最后一位143for  f in files:i1=f.split () [0].split (".") [0] #分割文件去除文件的后缀名if  a == i1: #判断ip最后一位是否跟去除后缀名的一样print  fprint  ' \033[31;1mruning  put:\033[0m %s  %s  '  %  (Ip, datetime.datetime.now ())   print  ' \033[31;1mfile:\033[0m ',  fsftp.put (Os.path.join (local_dir, f),  os.path.join (remote_dir, f)) print  ' \033[ 32;1mput success\033[0m %s  '  % datetime.datetime.now ()   print print   '-' *30t.close () except:print  "Conntect", Ipresult_list = []for h in host_ List:local_dir= "/put/" remote_dir =  "/put/" P = pool (processes=2) result_list.append (p.apply_ Async (Put,[h,local_dir,remote_dir]) for res in result_list:res.get ()

Let's take a look at the effect.

1. First I create a/put/directory on my server to store the files that need to be uploaded, the format of the file is as follows

127.txt 139.txt 143.txt

So I can upload it to the specified server based on the file name.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/80/wKioL1RpjI_hatg7AAH9K942FSs234.jpg "title=" 1.png " alt= "Wkiol1rpji_hatg7aah9k942fss234.jpg"/>


As can be seen, according to my definition of the file upload to the specified server above, because my script does not define 139 this machine, all this file is not uploaded, then we go to see the client 127,143/put/directory is consistent with the input, corresponding to the respective file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/82/wKiom1RpjFLQ2uxyAAChqUfqRqg607.jpg "title=" 2.png " alt= "Wkiom1rpjflq2uxyaachqufqrqg607.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/82/wKiom1RpjF-BBiykAACHfeuyxA8374.jpg "title=" 3.png " alt= "Wkiom1rpjf-bbiykaachfeuyxa8374.jpg"/>

This article is from the "Server" blog, so be sure to keep this source http://zhangfang2012.blog.51cto.com/6380212/1577409

Python uploads different file names to different servers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.