Как удалить файлы с помощью скрипта Python с FTP-сервера старше 7 дней?

Я хотел бы написать скрипт Python, который позволяет мне удалять файлы с FTP-сервера после того, как они достигли определенного возраста. Я подготовил нижеприведенный текст, но он выдает сообщение об ошибке:WindowsError: [Error 3] The system cannot find the path specified: '/test123/*.*'

У кого-нибудь есть идеи, как решить эту проблему? Заранее спасибо!

import os, time
from ftplib import FTP

ftp = FTP('127.0.0.1')
print "Automated FTP Maintainance"
print 'Logging in.'
ftp.login('admin', 'admin')

# This is the directory that we want to go to
path = 'test123'
print 'Changing to:' + path
ftp.cwd(path)
files = ftp.retrlines('LIST')
print 'List of Files:' + files 
#--everything works fine until here!...

#--The Logic which shall delete the files after the are 7 days old--
now = time.time()
for f in os.listdir(path):
  if os.stat(f).st_mtime < now - 7 * 86400:
    if os.path.isfile(f):
        os.remove(os.path.join(path, f))
except:
    exit ("Cannot delete files")

print 'Closing FTP connection'
ftp.close()

Ответы на вопрос(0)

Ваш ответ на вопрос