By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,991 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,991 IT Pros & Developers. It's quick & easy.

FileSystemWatcher and FTP

P: n/a
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!!!!

May 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Red2" wrote:
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!!!!

May 10 '06 #2

P: n/a
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. :)

"Red2" <sd******@gmail.com>
???????:11********************@q12g2000cwa.googleg roups.com...
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!!!!

May 11 '06 #3

P: n/a
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.

May 11 '06 #4

P: n/a
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.

May 12 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.