码迷,mamicode.com
首页 > 其他好文 > 详细

2.7 清除FTP服务器文件

时间:2017-10-14 15:00:44      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:dir   init   span   ==   etc   parse   oca   tool   elf   

清除服务器文件

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服务器文件

标签:dir   init   span   ==   etc   parse   oca   tool   elf   

原文地址:http://www.cnblogs.com/fg2312/p/7666836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!