python - unable to download files recursively using ftputil -


i trying write code should download files have been created in past 6 days. able print files not able download. please suggest wrong , me complete sript.

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')  root,dirs,files in ftp.walk('windows triage' , topdown=true):     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)             fname in name:                 fpath = ftp.path.join(root,fname)                 if ftp.path.isfile(fpath):                     ftp.download(fpath,os.path.join(dir_dest, fname), 'b') 

it looks not recursively descending directories.

enclose code in function

def f(dirpath):     root,dirs,files in ftp.walk(dirpath , topdown=true):         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)                 fname in name:                     fpath = ftp.path.join(root,fname)                     if ftp.path.isfile(fpath):                         ftp.download(fpath,os.path.join(dir_dest, fname), 'b')         curdir in dirs:             f(os.path.join(root, curdir)) 

and call with

f('windows triage') 

mind you: have not tried , have not used python ftp library yet.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -