我正在尝试下载过去 6 天内创建的文件,我可以打印文件的名称,但不能将文件从 FTP 服务器下载到本地系统。请提出我错在哪里。
import ftplib
import ftputil
import os
import datetime
now=datetime.datetime.now()
print (now)
ago=now-datetime.timedelta(days=6)
print (ago)
class MySession(ftplib.FTP):
def __init__(self, host, userid, password, port):
ftplib.FTP.__init__(self)
self.connect(host, port)
self.login(userid, password)
ftp = ftputil.FTPHost('host', 'user', 'pwd', port=21,
session_factory=MySession)
dir_dest=os.chdir('C:/Python34/New folder')
for root,dirs,files in ftp.walk('Windows Triage' , topdown=True):
for name in files:
path=ftp.path.join(root,name)
st=ftp.stat(path)
ctime=datetime.datetime.fromtimestamp(st.st_mtime)
if ctime>ago:
print(name)
for fname in name:
fpath = ftp.path.join(root,fname)
if ftp.path.isfile(fpath):
ftp.download(fpath,os.path.join(dir_dest, fname), 'b')