1. 程式人生 > >python 刪除ftp伺服器目錄

python 刪除ftp伺服器目錄

    解決這個問題: ftplib.error_perm: 550 Delete operation failed.

    def ClearPictPeriodly(self,iDay = 10):
        
        currentTime = datetime.datetime.now()
        currentDay = currentTime.day
        #notice
        if currentDay != 1 or currentTime.hour >= 2:
            return
        list =  self.ftp.nlst()
        print(list)
        for file in list:
#            self.ftp.sendcmd('rm -rf %s'%file)
            print("%s"%file)
            self.ftp.cwd(file)
            listPng = self.ftp.nlst()
            for png in listPng:
                self.ftp.delete(png)
            self.ftp.cwd("..")
            self.ftp.voidcmd('RMD ' + file)