4

Is there a way to run a script over a file that has been uploaded on an FTP server.

I am running ProFTP on the server and would like to process the uploaded files immediately after they are uploaded. The ways I have currently thought of are

  1. Cron Job to find new files in the FTP and process them every minute.
  2. Write a daemon to monitor the file upload log and use that information to process the file.

Is there a better way, or a directive I can set on the server to run a script on all file uploads?

Update: Linux OS

jW.
  • 155
  • 1
  • 2
  • 7

3 Answers3

4

You don't state your OS, but if you're on a Linux box, you can hook 'inotify', which will is a kernel subsystem that fires when filesystem events happen. This should give you much better response time than cron, which only runs on one minute granularity.

The following link will get you started, but there are Perl, Python, and a bunch of other bindings available.

http://inotify-tools.sourceforge.net

pboin
  • 1,096
  • 8
  • 11
3

If changing your ftp daemon is not a problem then pure-ftpd has this functionnality.

Hope this helps.

Maxwell
  • 5,076
  • 1
  • 26
  • 31
1

The two general approaches to this would be:

  1. Use functionality built-in to ProFTP (if it exists) or another FTP server product
  2. Have some operating system process or cron job (as you mentioned in both your #s 1 and 2) watch for the file, or better than polling is to watch for file system events and respond accordingly. See https://stackoverflow.com/questions/324258/is-there-an-equivalent-to-the-net-filesystemwatcher-in-the-linux-world.

The easiest approach is to use functionality built in to the FTP server if it exists. If not, you can likely download file watcher code and or an already-written shell script which you can cron.

Matthew
  • 529
  • 2
  • 6
  • 14