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?
I have about 500 remote dirs that I would like to perform an action on immediately (or at least very soon) when a new upload to that dir is detected. Is there such a "listen" script?

My goal is to move a file (or rename to a different location) as soon as it's uploaded?

Any suggestions would be helpful.
Hi Tim,

I have modified the script of this other forum topic:
Upload a file as soon as it appears
http://www.scriptftp.com/forum/general-f6/upload-a-file-as-soon-as-it-appears-t520.html


to do the opposite, as you suggested. Instead of watching new file in a local directory it checks for it in the FTP side.
FTP Script
  1. # This scripts checks if there is a new file in a set
  2. # of remote directories and as soon as the file appears
  3. # it moves it to another remote directory.
  4. # It is meant to be run periodically so this way it can
  5. # "watch" for incoming files in the FTP site.
  6. # Note that, if the file is being uploaded at the precise moment
  7. # this script runs, the action of moving the file to the destination
  8. # folder will fail but it will work on the next run if the upload
  9. # has finished.
  10.  
  11. # The remote directories to watch for incoming files.
  12. # Use | to separate them
  13. $incoming_dirs="/my_dir_1|/my_dir_2|/my_dir_2/subdir1"
  14.  
  15. # Once a new uplad is detected, the file is moved here
  16. $processed_files_dir="/my_destination_dir"
  17.  
  18. # Connect to the FTP server
  19. OPENHOST("127.0.0.1","test","1234")
  20.  
  21. FOREACH $remote_dir IN $incoming_dirs
  22.     # Change current remote directory
  23.     $result=CHDIR($remote_dir)
  24.  
  25.     # If CHDIR failed stop the script
  26.     IF($result!="OK")
  27.         STOP
  28.     END IF
  29.    
  30.     # Retrieve the list of files
  31.     $result=GETLIST($list,REMOTE_FILES,"*.*")
  32.  
  33.     # If GETLIST failed stop the script
  34.     IF($result!="OK")
  35.         STOP
  36.     END IF
  37.  
  38.     # Move all the found remote files to processed
  39.     # files dir
  40.     FOREACH $item IN $list
  41.         # For moving files in FTP we need to actually rename it
  42.         RENAMEFILE($item,$processed_files_dir."/".$item)
  43.     END FOREACH
  44.