1

As the title says, I need to monitor a remote folder for new files through a SFTP connection.

I setup a daemon process that opens a connection and if it finds any files then it retrieves their contents and if it doesn't then it sleeps for 5 seconds. This works fine it just hovers around 4% CPU usage. Is there a better way to do this and is it bad to keep a connection like this open indefinitely?

ginterUF
  • 11
  • 2
  • Why can't you do the reverse? Setup a daemon on the server with the file that can use OS hooks to only be woken when the folder actually changes and then have it ping your app. – Andrew Marshall Feb 03 '12 at 22:36

1 Answers1

1

That's probably the best thing you can do, given the circumstances. When watched directories get bigger, your daemon will likely run slower and consume more resources.

A single persistent connection is nothing, both on client and server. But if there are many clients, server may slow down.

If you control the other server, a much better way would be to install a daemon on it. Local process can listen to filesystem notifications and broadcast to connected watchers.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367