compare_file_dates.ftp

 

This script downloads every file that has been created today from the FTP server.

# Connect to the FTP server
$result=OPENHOST("10.8.0.1","carl","123456")
 
IF($result!="OK")
 PRINT("Error connecting to the FTP server. Stopping script.")
 STOP
END IF
 
 
# Set current local directory
$result=LOCALCHDIR("C:\test")
IF($result!="OK")
 PRINT("Error changing current local directory. Stopping script.")
 STOP
END IF
 
 
# Set current remote directory
$result=CHDIR("filesourcedir")
IF($result!="OK")
 PRINT("Error changing current local directory. Stopping script.")
 STOP
END IF
 
# Get remote file listing
$result=GETLIST($myremotefilelist,REMOTE_FILES,"*.*")
 
IF($result!="OK")
 PRINT("Error retrieving remote file listing. Stopping the script")
 STOP
END IF
 
# Get the current date
$currenttime=GETDATE(FORMAT0)
PRINT("Current time is ".$currenttime)
# The time is expressed in this format:
# AAAA_MM_DD-HH_MM_SS
# We need only the AAAA_MM_DD part.
$currentdate=TEXTCUT($currenttime,1,10)
 
 
 
# For each file in the list do the following
FOREACH $remotefile IN $myremotefilelist
 $filetime=GETFILETIME(REMOTE,$remotefile)
 IF($result!="OK")
 PRINT("Error getting the remote file time of ".$remotefile.". Stopping the script.")
 STOP
 END IF 
 $filedate=TEXTCUT($filetime,1,10)
 # Check if the file has been created today
 IF($filedate==$currentdate)
 PRINT("The file ".$remotefile." has been created today. Downloading.") 
 # The file has been created or modified today. Download it.
 $result=GETFILE($remotefile)
 IF($result!="OK")
 PRINT("Error downloading ".$remotefile.". Stopping the script.")
 STOP
 END IF 
 ELSE
 PRINT("The file ".$remotefile." has NOT been created today. Skipping.")
 END IF
END FOREACH
 
CLOSEHOST()