2.7 清除FTP服务器文件
Posted 啊峰哥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.7 清除FTP服务器文件相关的知识,希望对你有一定的参考价值。
清除服务器文件
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服务器文件的主要内容,如果未能解决你的问题,请参考以下文章