Script

FTP

The professional tool to automate FTP, SFTP, FTPS and Batch FTP

  • Home

  • FORUM INDEX
Need help writing a script? Have any question about ScriptFTP?
 #14948  by Dr0id
 15 Feb 2017, 16:04
Hi guys,

so i'm trying to create a script based on the currentday script in the script library. Wich will download yesterdays and currentdays file.

Here what I did:
FTP Script
  1.  
  2. # Connect to the FTP server
  3. $result=OPENHOST("#####","####","#####")
  4.  
  5. IF($result!="OK")
  6.  PRINT("Error connecting to the FTP server. Stopping script.")
  7.  
  8.  
  9. # Set current local directory
  10. $result=LOCALCHDIR("Z:\_BOX_")
  11. IF($result!="OK")
  12.  PRINT("Error changing current local directory. Stopping script.")
  13.  
  14. # Set current remote directory
  15. $result=CHDIR("/remote/Files/")
  16. IF($result!="OK")
  17.  PRINT("Error changing current local directory. Stopping script.")
  18.  
  19. # Get remote file listing
  20. $result=GETLIST($myremotefilelist,REMOTE_FILES,"*.*")
  21.  
  22. IF($result!="OK")
  23.  PRINT("Error retrieving remote file listing. Stopping the script")
  24.  
  25. # Get the current date
  26. $currenttime=GETDATE(FORMAT0)
  27. # The time is expressed in this format:
  28. # AAAA_MM_DD-HH_MM_SS
  29. # We need only the AAAA_MM_DD part.
  30. $currentdate=TEXTCUT($currenttime,1,10)
  31.  
  32. #Get yesterday date
  33. # Then, you can substract or add seconds to that date stored
  34. # in the variable. Yesterday is:
  35. $currenttime=GETDATE(FORMAT0)
  36. $yesterday=$currenttime-(86400)
  37. $yesterday=TEXTCUT($yesterday,1,18)
  38.  
  39. PRINT("Current time is ".$currenttime)
  40. PRINT("Yesterday date is ".$yesterday)
  41.  
  42. # For each file in the list do the following
  43. FOREACH $remotefile IN $myremotefilelist
  44.  $filetime=GETFILETIME(REMOTE,$remotefile)
  45.  
  46.  IF($result!="OK")
  47.  PRINT("Error getting the remote file time of ".$remotefile.". Stopping the script.")
  48.  END IF
  49.  
  50.  $filedate=TEXTCUT($filetime,1,10)
  51.  # Check if the file has been created today
  52.  
  53.  IF($filedate==$yesterday)
  54.  PRINT("The file ".$remotefile." has been created yesterday. Downloading.")
  55.  # The file has been created or modified yesterday. Download it.
  56.  $result=GETFILE($remotefile)
  57.  
  58.  IF($filedate==$currentdate)
  59.  PRINT("The file ".$remotefile." has been created today. Downloading.")
  60.  # The file has been created or modified today. Download it.
  61.  $result=GETFILE($remotefile)
  62.  
  63.  IF($result!="OK")
  64.  PRINT("Error downloading ".$remotefile.". Stopping the script.")
  65.  END IF
  66.  PRINT("The file ".$remotefile." has NOT been created today. Skipping.")
  67.  
  68.  
Let me know what you think. Thanks everyone
-->