Script

FTP

The professional tool to automate FTP, SFTP, FTPS

and schedule FTP batch jobs

MENUMENU

Uploading only the files created or modified in the last 7 days



 

The following script shows how to upload to the FTP server the files from the last 7 days. If a file is more than 7 days old it will be ignored.

Note that this example does not work with subfolders.

 

 

# Connect to the FTP site
OPENHOST("ftp.myserver.com","johndoe","1234")
 
# What time is it?
$today = GETTIME()
 
# ScriptFTP handles time spans in seconds. See:
# https://www.scriptftp.com/b/handling-file-dates-and-time-spans
$seven_days_in_seconds = 7 * 24 * 60 * 60
 
PRINT("Today is: ".$today)
PRINT("Seven days in seconds is: ".$seven_days_in_seconds)
 
# We are uploading the files from local_folder to remote_folder
$local_folder = "C:\Users\JohnDoe\Desktop\The Files"
$remote_folder = "/my_folder"
 
# Change the current local folder 
LOCALCHDIR($local_folder)
 
# Change the current remote filder
CHDIR($remote_folder)
 
# Get the listing of the local folder
GETLIST($local_file_list,LOCAL_FILES)
 
# For each file in the local folder
FOREACH $file IN $local_file_list
 
	# what is the date of this file?
	$file_time=GETFILETIME(LOCAL,$file)
 
	# We only upload the file if it is not older
	# than a week.
	IF(($today - $file_time) < $seven_days_in_seconds)
		PUTFILE($file)
	ELSE
		PRINT("The file is older than a week. Skipping this file")
	END IF
END FOREACH
 
# Say goodbye to the FTP server and close the connection
CLOSEHOST