Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run PHP script when a new file is added via FTP

Tags:

linux

php

ftp

I have multiple cameras sending images at random intervals via FTP to a predetermined folders.

For example:
recordings/camera1/images/ - for first camera
recordings/camera2/images/ - for second camera
etc

Each of them save images in .jpg format and then close FTP connection.

I need to call a PHP script after each time a new file is added. Let's say whenever a new image is added into the /recordings folder I need to call the php script with

newimage.php?location=recordings/camera1/images/picture002.jpg

and so on.

The server is a Linux box running ProFTPD

How I can get this done?

Please note: Cron job is not an option as there will thousands of files and we are not using a DB. So we cannot find out if there are any new files.

like image 616
ToughPal Avatar asked Jan 23 '23 13:01

ToughPal


1 Answers

I would advise you to take a look at the mod_exec of ProFTPD. Here is a quote explaining its goal:

The mod_exec module can be used to execute external programs or scripts at various points in the process of handling FTP commands. By conscious design, ProFTPD does not and will not execute external programs. This is a security decision, as it was decided not to allow ProFTPD to serve as a means of compromising a system or disclosing information via bugs in external programs or scripts. Use of this module allows for such external programs to be executed, and also opens up the server to the mentioned possibilities of compromise or disclosure via those programs.

You can also take a look at inotify which offers you to monitor system file activity.

like image 105
Boris Guéry Avatar answered Jan 29 '23 08:01

Boris Guéry