#!/bin/bash use strict; use warnings; use diagnostics; # Login credentials user='*****' #Do not forget to enclose inside single or double quotes pass='*****' directory='Remoredirectory' host='RemoteIP' # Set time # perl -e 'print time' will return the current time in Unix epoch format # So if you substract 43200, that should give you the current time minus 30 minutes in Unix epoch format: time=$(perl -e 'print time-43200') # Connect to host and download the listing of the remote directory ftp -n $host < /Localdirectory/'Dates.txt' # Save the 9th field of the directory listing (file name) of each line into file Files.txt awk -F ' ' '{print $9}' /Localdirectory/ftpList.txt > /Localdirectory/'Files.txt' linenum=0 #Auxiliary variable for sed. while read list; do linenum=$((linenum+1)) #Convert the modification datetime of each file to Unix's epoch epoch=$(perl -MFile::stat -e "print stat('$list')->mtime") if [ $epoch -gt $time ] ; then file=$(sed -n "${linenum}p" Files.txt) #If the condition is satisfied, use sed to get the name of the file #in the same line of Files.txt. #Connect again and download file when the condition above has been satisfied. ftp -n $host <