is the main study of Python programming to delete server files, the specific implementation of the code as follows.

1

 #coding:utf-8 import instance paramiko "create a file to delete the file root permission" (ssh=paramiko.SSHClient) ssh.set_missing_host_key_policy (paramiko.AutoAddPolicy) (ssh.connect) (hostname= "192.168.1.37" port= 22 username= "test" password= "test") stdin, stdout, stderr=ssh.exec_command ('sudo -i touch /a.txt'get_pty=True (stdin.write) the "testn") # stdin.write ("n") (stdin.close) (stdout.close) (print) (stderr.read) (stderr.close) stdin, stdout, stderr=ssh.exec_command ('sudo -i RM -f /a.txt', get_pty=True) stdin.write ("testn") # stdin.write ("n") (stdin.close) (print (stderr.read) (ssh.close) 

2

) examples of users of WeChat directory for users to upload pictures of more years of hard disk, resulting in resources will be exhausted, but to the customer requirements Little save a month

file, but hundreds of thousands of pictures of the folder, whether it is open, ranking are deleted consuming server performance, because the large consumption of loading this more than 10 G file will cause CPU and memory, so write a python script from 30 days before the move to delete the file

the following code:

 coding:utf-8 import OS #-*- -*- import time import datetime f = list (os.listdir ("G:\qtp") for I in (len) range (f)): filedate = os.path.getmtime ("G:\qtp\" + f[i]) time1 = datetime.datetime.fromtimestamp (filedate).Strftime ("%Y-%m-%d") date1 = time.time (num1) = (date1 - filedate) /60/60/24 if num1 > 30: = os.remove ("G:\qtp\" + f[i] (print) deleted files:%s:%s% (time1, f[i]) else:) Print ("there are no file more than 30 days 

") results:

h2>

is the < / summary all the content on the python server delete file code examples, we hope to help. Interested friends can continue to refer to other relevant topics of the station, if there are shortcomings, welcome the message. Thank you for the support of our friends!

This paper fixed link:http://www.script-home.com/python-delete-server-file-code-examples.html | Script Home | +Copy Link

Article reprint please specify:Python delete server file code examples | Script Home

You may also be interested in these articles!