lftp to sync folders but do not keep files older than 30 days old on synced machine.

rafaelrgl used Ask the Experts™
here is what I did:

lftp ftp://ftp.server.com <<- DOWNLOAD
    user user@ftp.com "password"
    set ssl:verify-certificate no
    mirror -cn / /localfolder;

this script works perfect to get the root folder on the ftp and sync with local folder, but here is what I want to accomplish now. I want to keep in my local folder only files that are newer than 30 days old base on the creation date of the file. So here is the example. lets say we run the script, the script will go to the ftp and download only the files that are newer than 30 days old and we do not have it inside the local folder and we will delete files older than 30 days on local folder. How can I accomplish this?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
Distinguished Expert 2018
You can use the mirror command with the option "-N now-30days"   (without ") or --newer-than=now-30days     added.

For local deletes try:
find /localfolder -type f -mtime +30 -print0 | xargs -0 rm -f

find will make a list of files (not directories) older than 30 days and print the list to xargs which will call rm on all the files in batches.


perfect. works like its suppose to. thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial