Python remote statistics file code sharing

Source: Internet
Author: User
It is a simple and practical function code for Python to obtain the remote file size. It is a basic instance for learning Python programming. Python remote statistics File

#! /Usr/bin/python # encoding = utf-8import timeimport osimport paramikoimport multiprocessing # count the number of files def get_total (ip, password, filepath): paramiko. util. log_to_file ('paramiko. log') ssh = paramiko. SSHClient () ssh. set_missing_host_key_policy (paramiko. autoAddPolicy () try: starttime = time. time () ssh. connect (hostname = ip, port = 22, username = 'root', password = password) # stdin, stdout, stderr = ssh.exe c_command (str (len (OS. listdir (filepath) stdin, stdout, stderr = ssh.exe c_command ('CD filepath; ls | wc-l') # print ip, filepath, stdout. read (). strip ('\ n') count = int (stdout. read (). strip ('\ n') endtime = time. time () caltime = endtime-starttime result = ip + ',' + filepath. strip ('\ n') +', '+ str (count) +', '+ str (caltime) +' \ n' return result counter T: result = ip + ', '+ filepath. strip ('\ n') +', '+ 'failed' +' \ n' return result#, ip.csv each row is 192.168.1.1, 111111,/var '). readlines () # Save the statistical result ipresultlist = ['IP, FILEPATH, COUNT, TIMECOST \ n'] # multi-process Statistics pool = multiprocessing. pool (processes = 6) # collect statistics for ip in iplist: ipin = ip in each row. split (',') Comment ', 'a +') fp. writelines (ipresultlist) fp. close ()

The above is all the content of this article. I hope you will like it.

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.