Prevent access of busy file

cellenbu

New member
Joined
Jan 31, 2003
Messages
1
I am now in the process of rewriting mountains of ASP classic stuff. I have one page that accesses a file that is FTPd up every 5 minutes. Sometimes the file is in the process of being FTPd when the ASP page tries to access it. This results in an empty file.

Im hoping that in VB.net, there is a way to detect whether the file is being FTPd or not.

Thank you for your time,
Chris
 
I dont honestly think there is one. What you can do depends on how the FTP server has the file opened. It might me that you can open the file and check for a length of 0, or you could try opening the file for write and trap an exception, that ought to work.

Alternatively, I found this solution which uses the OpenFile to ascertain if a file is opened by another process or not. Youd have to port from VB6 calling API, to VB.NET but it might be an answer.
 
If you can provide a simple web server then the clients could call a simple webservice to notify your process that a file has arrived.

Also, you could require that each client uploads a small "alldone.txt" type of file after the main file. Your process could then check for the existence of the dummy file to indicate the first one is finished. This works well if each client has their own directory they upload to or a standard naming convention for their uploads.

-nerseus
 
I use this:

Code:
   Dim fl as New System.IO.Filestream(filetowrite,FileMode.OpenOrCreate,FileAccess.Write,FileShare.None)

this locks the file so that no other client can read or write the file. But you can also use FileShare.Read instead, this will share the file for reading only, so that the client can continue to read the file when its being rewritten.
 
Back
Top