[Python] 纯文本查看 复制代码 class FtpController:
def __init__(self, host, username, password):
ftp_server = ftplib.FTP(host)
ftp_server.encoding = "utf-8"
ftp_server.login(username, password)
self.ftp = ftp_server
def del_all_file(self, ftp_path):
self.ftp.cwd(ftp_path)
files = self.ftp.mlsd()
# 清空当前目录
for file in files:
if file[1]['type'] == 'dir':
self.del_all_file(file[0])
if file[1]['type'] == 'file':
self.ftp.delete(file[0])
# 删除当前目录
self.ftp.rmd(".")
# 退回到上级目录
self.ftp.cwd("..")
if __name__ == '__main__':
print_hi('PyCharm')
ftp = FtpController("localhost", "admin", "admin")
ftp.del_all_file("/com/example") |