tags:

views:

275

answers:

1

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?

+1  A: 

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"
Goran Jurić
5. Maintain a list of file hashes so you can detect when a file is changed.
Marko
@Goran - That's pretty much the strategy that occurred to me, but I'm really worried it wouldn't scale at all well.
Ciaran McNulty
In the end it depends on the number of files and folders that will be stored on that share.
Goran Jurić