1. 程式人生 > >2.7 清除FTP服務器文件

2.7 清除FTP服務器文件

files run nal 文件 判斷 iss miss logs name

清除服務器文件

from ftptools import FtpTools

class CleanAll(FtpTools):
    ‘‘‘delete an entire remote tree of subdirectories‘‘‘

    def __init__(self):
        self.fcount = self.dcount = 0

    def getlocaldir(self):
        return None

    def getcleanall(self):
        return True

    def cleanDir(self):
        lines 
= [] self.connection.dir(lines.append) #每個文件Lines都不同 for line in lines: parsed = line.split() permiss = parsed[0] #判斷drw... 文件名 fname = parsed[-1] if fname in (.,..):continue
elif permiss[0] != d: print(file,fname) self.connection.delete(fname) self.fcount += 1 else: print(directory,fname) self.connection.cwd(fname) self.cleanDir() self.connection.cwd(
..) self.connection.rmd(fname) self.dcount += 1 print(directory exited) if __name__ == __main__: ftp = CleanAll() ftp.configTransfer(site=192.168.191.1, rdir=.,user=‘‘) ftp.run(cleanTarget=ftp.cleanDir) print(Done:, ftp.fcount, files and, ftp.dcount, directory cleaned.)

2.7 清除FTP服務器文件