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.