ftp automation

ScriptFTP

The professional tool to automate FTP, SFTP, FTPS and schedule FTP batch jobs

The forum is now read only. Please, go to the the main ScriptFTP website if you need help.
Need help writing a script? Have any question about ScriptFTP?
Hi All,

how can i upload files that are older than two days?

thanks,
Hi sumation, thanks for posting your question here. Try the following:
FTP Script
  1. # Connecto to the FTP server
  2. OPENHOST("127.0.0.1","test","1234")
  3.  
  4. # Change current remote directory
  5. CHDIR("/remote_destination_dir")
  6.  
  7. # Change current local directory
  8. LOCALCHDIR("C:\mylocaldir\")
  9.  
  10. # Retrieve current date and time
  11. $current_date_time=GETDATE(FORMAT0)
  12.  
  13. PRINT("Current date and time is ".$current_date_time)
  14.  
  15. # Substract two days (in seconds) from the current date,
  16. # assign the result to another variable
  17. $two_days_ago=$current_date_time-(2*24*60*60)
  18.  
  19. PRINT("two days ago was ".$two_days_ago)
  20. PRINT("Every file older than this will be uploaded to the FTP server")
  21.  
  22. # Request the remote file list
  23. GETLIST($local_file_list,LOCAL_FILES)
  24.  
  25. # For each file in the current local directory
  26. # check if it is older than two days. If so upload it
  27. FOREACH $local_file IN $local_file_list
  28.     $file_last_modification_time=GETFILETIME(LOCAL,$local_file)
  29.     IF($file_last_modification_time<$two_days_ago)
  30.     PUTFILE($local_file)
  31.     END IF
  32.  
It works,
one bit of an issue is script uploads other files that are not in the path.

i.e.
FTP Script
  1. # Change current remote directory (this is the FTP server and the path where to upload, and it works)
  2. CHDIR("/test")
  3.  
  4. #this is the path there is going to get the files to upload, but is taking files that are not in the folder.
  5. PUTFILE("C:\Users\Ed\Desktop\newfolder\*.zip")
what could be the problem.
Last edited by sumation on 22 Dec 2014, 21:21, edited 1 time in total.
the problem was that with the following line it was getting almost all the local files and uploading them.
FTP Script
  1. GETLIST($local_file_list,LOCAL_FILES)
so I removed it.
Thank you for your time and efforts!
the problem was that with the following line it was getting almost all the local files and uploading them.
do you mean that GETLIST was giving you files that were in subfolders? This should not happen unless you use GETLIST(....., SUBDIRS), and it seems that you have not used it. Could you confirm this?
I was uploading files from all over and i had no subdirectory.
so a commented #GETLIST($local_file_list,LOCAL_FILES) and the problem was solved, Only uploaded what ever as 2 days old with zip ext.

Thanks again !
thanks for your reply :)