FileSystemWatcher and FTP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've being looking for a root-cause for the following problem (currently
have a work-around):-

We have a .NET FileSystemWatcher watching an FTP directory. The FTP
folder/account is on a Windows 2003 Server system (SP1), and the FTP account
is configured with user isolation.


The C# code is very simple, when the watcher triggers a Created event, it
copys the file to another location and then removes the original.

Now, if I manually drop a file into the watched directory, everying works.
If I use FTP Put to place a file there, I get an error saying that the file
cannot be copied as another process is accessing it.

My workaround is a 30 minute delay to ensure the FTP session closes, then
copy the file. It works fine.

Is there a better way of solving this? (e.g. ftp uploads of large files over
slow connections may take longer than 30 mins).

Help appreciated.



The process is failing at the copy stage (using File.Copy() ), reporting an
error
 
Hi Craig,

I think you've got the basic idea correct. There is no way to know when the
file is created, how long it will take for the FTP server to finish writing
it, as it will be of varying lengths, and taking network and FTP latency
into account. You might want to set up an interval and retry every few
seconds, but the only way to know when the file is complete is when it is
released by the FTP process.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"craig@amtdatatechnologies"
 
Thanks for reply :)

It take it there is no way to detect whether no other processes are
accessing a file?
 
I setup mine to attempt to open the file for exclusive access to determine if I
have rights to copy or move the file. Retries every n seconds until successful.

HTH,

ChrisG
 
Hi Craig,

There are ways, but the simplest is to simply try to access the file. For
example, you could bind to the process and monitor it, but that is just too
much overhead and complexity.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"craig@amtdatatechnologies"
 
Back
Top