how to lock a file in ftp site

Ben Hutchings ben-public-nospam at decadentplace.org.uk
Tue Dec 20 18:40:08 CET 2005


<muttu2244 at yahoo.com> wrote:
> hi all
>
> 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.
>
> so is there a way in Python script where i can lock the file, so that
> no one updates it until i release the lock.

A common means of cooperative file locking is to use the existence of
a second file as a lock indicator.  I'm not sure that can be done over
FTP, though, because I think when you write to such a file you can't
tell whether it existed previously (which would mean someone else
owned the lock).

> Or is there a way where i can directly update the file from the ftp
> itself, i mean without downloading it to my local machine.
>
> Thanks in advance for the help

You should probably switch from FTP to a version control system, such
as CVS or Subversion.  They don't normally use locking, but they do
detect conflicting changes and stop you from overwriting other
people's changes.

-- 
Ben Hutchings
Every program is either trivial or else contains at least one bug



More information about the Python-list mailing list