1.

Solve : ftp commands?

Answer»

Hi all,

I'm cracking my head with a small and simple thing, that unfortunately seems out of reach for my head...
I need to transfer files from a ftp server to my computer in a automatic way. The problem is that the FOLDER in the ftp, were these files are, acts as a backup as well, having files with 3 weeks OLD. Is there a way of SORTING the files by date, and just download these ones instead of everything?

Thanks in advance

Regardsthe windows ftp client that came with INSTALLATION is primitive. Instead, use a programming language, eg Python (or any others) that provides you FTP libraries for file transfer. eg in Python
Code: [Select]import ftplib
server="localhost"
user="anonymous"
password="[email protected]"
filelist=[]
DEF download(ftp, filename):
    ftp.retrbinary("RETR " + filename, open(filename,"wb").write)
try:
   ftp = ftplib.FTP()
   ftp.debug(3)
   ftp.connect(server,21)
   ftp.login(user,password)
except Exception,e:
    print e
else:
    ftp.cwd("directory to change if any")
    ftp.retrlines('LIST',filelist.append)
    for latest in filelist:
        if latest.startswith("-") and "latest file pattern if any" in latest:
            print latest
            download(ftp,latest)
    ftp.quit()
sys.exit()

this assumes that your old files are named in a distinct format, such as file.bak or something, and your latest file is not in that format.

usage:
Code: [Select]C:\test> python myscript.py



Discussion

No Comment Found