unable to download files using ftputil

1.3k Views Asked by At

I am trying to download files which have been created in past 6 days, I'm able to print the names of the files but not download the files from the FTPserver to the local system. Please suggest where I'm wrong.

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')
0

There are 0 best solutions below