how to lock a file in ftp site

Kinsley Turner kingsleyturner at westpac.com.au
Mon Dec 19 17:37:58 EST 2005



> am trying to write some information into the file, which is located in
> ftp, and this file can be updated by number of people, but if at all i
> download a file from the ftp to my local machine, update it and then
> upload it back to ftp, and at the same time if some one else downloads
> the same file for the modification, then the data will be overwritten.

As far as I'm aware, there's no way to 'lock' a file via FTP.
Some FTP servers might give this sort of functionality, but then
your solution becomes system dependant.

A simple sort of solution might a 'lockfile'.  When you want to
edit this remote file, your machine checks for '<filename>.lock'
which contains (*shrug*) the IP address/username/timestamp of the
person editing the file.  If it doesn't exist, it should try to
create the file, then check again that it indeed managed to get
it's name into the lock.  You still have a contention issue with
multiple-users uploaded the lock-file at the same time.  So on
the re-check, if the file is corrupt, it can be deleted, otherwise
if the lock-owner is you, the edit may continue.  Once the edit
is complete, the lockfile is removed.

You might have to think about the lockfile mechanism a bit - If
you find the lockfile is corrupt (i.e.: more than 1 client tried
to write it at the same time), would you erase it then wait some
random period of seconds?  or just try to achieve the lock again?

What about stale lockfiles?  If the timestamp of the file is more 
than N hours/minutes/seconds old, can anyone remove it?

Anyway, a 100% complete solution to this problem might be difficult,
but a 99% solution is fairly easy.

hope this helps,
-kt

























(obnoxious corporate .sig follows)
--


Please consider our environment before printing this email.

WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately.

It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments.


This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision.

Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency.

Westpac Banking Corporation ABN 33 007 457 141.



More information about the Python-list mailing list