I am download file from FTp by File watcher .when 1 file is downloading so others can not download that file
How can i do this i have no idea one of my friend telling use locking mechanism
will it help me or something else should be used
I am working with C# (windows application)
Thanks
Loading
Sam HobbsPosted Jul 13, 2011, 7:41 PM
Just imagine a situation in which remote client puts an OS lock on an FTP-hosted file and then crashes before removing the lock, or simply loses connection to FTP server. The lock would then remain indefinitely, and that should not be allowed.
Perhaps you just did not make clear what you meant, but this is saying that the remote client can create a lock in the server. Is that what you meant?
Zoran HorvatPosted Jul 13, 2011, 6:35 PM
Locks are put on file when file is open, and that is in this case done by FTP server on its own. Locks are different from attributes in that attributes are persisted on file storage, while locks are maintained in memory by the OS. File attributes like read only, system file, ready for archiving, etc. cannot be used to control access to the file by multiple readers. That can only be done using locks obtained when file is opened by one particular reader, i.e. process, and lock is further on associated with that process. Once the process closes the file and releases file handle, lock is removed.
FTP client does not possess the file handle, and thus cannot control the locks. On the other hand, FTP server does not grant any low-level access to the client - it merely allows client to say which file to download and how (actively or passively), and that's it. Actual access to the file, in sense of reading or writing parts of the file are maintained by the FTP server internally and FTP clients cannot affect or sense that.
When you say that you have changed file's attributes on FTP, what exactly did you do?
Zoran
Sam HobbsPosted Jul 13, 2011, 6:02 PM
Things like the file's attribute is a property of the file. It is static until changed with another setting.
I am not sure what the lock is, but it does seem to be something that is temporary for the life of an access to a file; that is why I said "something that is specified in a program".
I know that there must be a way to change a file's attributes using FTP because I have done it.
I was hoping that there would be a file attribute or mode or something that will allow only one access at a time, but probably not.
The question I asked is if this is for just one system or multiple systems. That might affect the solution.
Zoran HorvatPosted Jul 13, 2011, 4:51 PM
It is quite different when putting locks on local system files, because every lock is then associated with the process handle. As soon as process dies, no matter how, its handle is removed from the system and all associated resources are released as well, which means that file locks are removed by OS if process doesn't remove them on its own.
Hence, I don't think that there is much hope regarding this thread.
Sam HobbsPosted Jul 13, 2011, 4:20 PM
I am not sure how locks work but I think it is something that is specified in a program but I think it is not a mode or attribute specified for a file. The FTP protocol is old and limited in its capabilities.
Note that you are not clear about what you mean by "others". It is not clear if that is within your computer or a single computer or if it is the entire internet everywhere in the world or something else.
Zoran HorvatPosted Jul 13, 2011, 8:32 AM
You can't lock files on FTP server because FTP server is maintaining locks in its own ways (which boils down to file system locks in usual manner). Here is the list of all FTP commands: http://www.nsftools.com/tips/RawFTP.htm
It shows all possibilities available to FTP client.
In case that your application is the "others" for whom you would like to lock the file, then typical method to solve the problem is to upload a small control file to the FTP server, which indicates a semantical lock - instance of the application which successfully uploads the file is the one to have the lock. Once it completes its operations, it should remove the uploaded file so that other instances can proceed with their operations. However, this solution must be coded very carefully, because of race conditions and possible failures in the application, after which lock would remain indefinitely.
Zoran