-1

We are using IIS for our ftp server and I would like to write either a c# windows service or a HTTP handler/module that would know that that a file has been ftp'd to a folder so that I can then them move it to another folder as well as updating a database.

My concern is if I do not know if the file has finished FTP (ing) to a folder then if I try to do something with it I would get a file access error.

JD.
  • 15,171
  • 21
  • 86
  • 159

2 Answers2

1

You can create a FileSystemWatcher on the folder watching for file create events.

However, as you noted, you have to be concerned that the file is in flight. To deal with this, you can use the FileSystemWatcher to enqueue the file name to a processor that watches/waits for the file to become closed. Here's a slightly hacky way you might check for whether the file is closed: Is there a way to check if a file is in use?.

There are lower-level approaches, but this gets you in the door. FileSystemWatcher has issues - it's easily overloaded - so if this is a "busy" folder, you might implement your own poll-and-compare rather than relying on it.

Community
  • 1
  • 1
Clay
  • 4,999
  • 1
  • 28
  • 45
1

This has already been answered in this question Does IIS FTP include an API to detect when a file upload completes?

Essentially you can use a custom logging provider.

Community
  • 1
  • 1
snoopy-do
  • 605
  • 4
  • 16