FileSystemWatcher and FTP

R

Red2

Hi all,
I have a little problem. I'm watching a directory on a server for
a FTP file to come in. I'm using FileSystemWatcher to catch the file
create event. Most cases this work fine. However sometimes when the
FTP is slow I get a error because another process is using the file.
This is because the FTP is still writing the file.
Is there a elegant way to prevent this. (I've thought of doing the
try/catch and loop untill it's free)

Thanks for the HELP!!!!
 
G

Guest

There are a couple of workarounds for this, depending on if you have control
over how the file is sent in.

1) have the file FTP'ed and then have it send a small control text file that
tells you the fTP transfer is finished. If you don't find the control file
after a watcher event, you know it's not finished transferring yet.

2) attempt to open the file and catch the exception. If exception sleep the
thread for a period and keep trying until no exception. Once you have access
to the file without any exceptions, it should have finished transferred.

3) More elegant solution _______________ (fill in the blank here).

Peter
 
L

Lau Lei Cheong

If you're using FTP of IIS, if you compare and find the "create time" and
"last modify time" differs, download is completed. (While IIS is still
writing on it, both "times" are the same)

Others are subject to implementation. You have to try, and you should know
what possibilities to look for now. :)
 
C

Chris Dunaway

another option is to have the file FTP'd using a temporary filename and
then when copying is complete, renamed to the final destination name so
that your file watcher will see it.
 
R

Red2

Thanks for all the help.

I have no control of the FTPing system unfortunitly. Comparing the
times didn't seem to work. So i'm going the access the file catch the
error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top