Question

I'm writing a PHP process that will run on a Unix machine that will need to monitor a remote SMB server and detect new files that are being uploaded to that box via FTP. It's unlikely I'll be able to

It will need to detect:

  1. New files being created
  2. File upload completing
  3. Files being deleted

If it was an NFS share, I'd try using FAM to detect the events, but I can't see a way of doing anything equivalent?

Was it helpful?

Solution

Doesn't sound like something I would use in production. But you could try something like this:

  1. mount the SMB share with Samba on the machine that is running a PHP daemon
  2. use SPL RecursiveIteratorIterator with DirectoryIterator to collect and maintain a list of all the files and folders on the shared drive
  3. once in a while refresh the folder list and compare it with the current state, if the file does not exist any more you know it has been deleted, if there is a new file put it in the queue and mark it as "being uploaded"
  4. in the next "refresh run" check the queued file, it the file size did not change the file upload probably completed, if the file size changed put it in the queue again and mark it as "being uploaded"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top