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?
would need help creating a script that connects to a remote ftp server and deletes files older than 1 month
Hi,

There is a script in the example section that shows how to delete the files older than a week. Chaning the $a_week_ago value to the right amount of seconds will do that:

https://www.scriptftp.com/s/average-scripts/older_than_a_week-ftp

FTP Script
  1. # Connecto to the FTP server
  2. OPENHOST("ftp.myhost.com","antonia","123456")
  3.  
  4. # Change current remote directory
  5. CHDIR("/directorytobeprocessed")
  6.  
  7. # Retrieve current date and time
  8. $current_date_time=GETDATE(FORMAT0)
  9.  
  10. PRINT("Current date and time is ".$current_date_time)
  11.  
  12. # Substract a month (in seconds) from the current date,
  13. # assign the result to another variable
  14. $a_month_ago=$current_date_time-(30*24*60*60)
  15.  
  16. PRINT("A month ago was ".$a_month_ago)
  17. PRINT("Every file older than this will be deleted from the FTP server")
  18.  
  19. # Request the remote file list
  20. GETLIST($remote_file_list,REMOTE_FILES)
  21.  
  22. # For each file in the current remote directory
  23. # check if it is older than a week. If so delete it
  24. FOREACH $remote_file IN $remote_file_list
  25.  $file_last_modification_time=GETFILETIME(REMOTE,$remote_file)
  26.  IF($file_last_modification_time < $a_month_ago)
  27.  DELETEFILE($remote_file)
  28.