Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm looking for input from the community for a utility that can set up a filesystemwatcher, ie, it can hook into File System events that detect when a file is created in a specific directory, and then be able to perform commands once that happens.

So here's my scenario:

  • Configure this utility (ideally a windows service?):
    • to watch C:\SpecialWatchedDirectory1
    • if a .SQL file is created, run a batch file, "ExecuteSchemaUpdate.bat %1"
  • set up FTP, enable uploads to "C:\SpecialWatchedDirectory1"
  • I upload a SQL script, ie, "DBSchema1.sql" and it runs.
  • since this utility looks for CREATED files, the script doesn't move the file out, it just waits for the next file to be uploaded.
  • I upload DbSchema2.sql and it runs "ExecuteSchemaUpdate.bat %1" again.

I'm looking for an alternative than have a scheduled task to poll the directory every 5 minutes.

share|improve this question
I wrote a very simple FileSystemWatcher in C# a couple of weeks ago. It was literally like 20 lines of my own code, Visual Studio just does the rest for you. Have you considered rolling your own? In all seriousness, it took about the same time to write this comment as it did write and compile that program :-) –  Ben Pilbrow Apr 19 '11 at 19:43
There is a flaw in your scenario. What if your .SQL file ends up being 50MB? Your .sql file will be created long before all the data is actually in it. Check and see if your FTP server can execute commands on uploaded files (or if you can find one that can do so). If not, then you should plan your upload script to upload the file as .tmp then when its uploaded have the ftp client rename the file to .sql. –  DerfK Apr 19 '11 at 19:53
@DerfK Your concern is noted, and the same case could occur for a polling mechanism. In theory, the utility would attempt to acquire a no-shared lock on the file and fail if it was still actively being written to. –  enorl76 Apr 19 '11 at 20:16
@Ben I have written several, and it seems like such a common thing that there would be a package that does so, that has a lot of these things "out-of-the-box", not to mention a growing user familiarity with it ;) –  enorl76 Apr 19 '11 at 20:18
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.