473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

how to lock a file in ftp site

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.

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

regards
yogi

Dec 19 '05 #1
4 2232
No, I think you have to manually set this policy directly on the ftp server.
Dec 19 '05 #2
mu*******@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.

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

regards
yogi

I've come across this problem - instead of uploading the file to it's

intended directory, upload it to a temp directory, with a unique name
(say uuuuuyyyymmddhhmmss where uuuuu is username and the rest are
obvious) and then *rename* it to it's correct name in the real
destination directory. Do the move in a try... except block and if it
fails, take evasive action.

In FTP a rename (i.e. move) is usually an atomic action but an upload is
not. You have an unavoidable race condition here trying to lock a file
(even if ftp allowed it) but with the method described above, you can
avoid it, but get the same effect.

Hope that helps!
-andyj

Dec 19 '05 #3
<mu*******@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
Dec 20 '05 #4
Ben Hutchings wrote:
<mu*******@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).

Well of course you could place a lock on the lock file before you tested
for its presence by creating another file ...
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.

I'm not sure a version control system is right for the OP's needs, but
clearly unadorned FTP isn't going to hack it either.

This being the Python, of course, it would be relatively simple to
design a protocol that would provide the required functionality and then
build clients and servers for that protocol. But we don't know whether
that's an option yet.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Dec 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: xmp333 | last post by:
Hi, I know the noresize attribute will keep the user from resizing a frame, but is there a way to keep a frame from being resized by the browser (in response to things like different...
3
by: jamie | last post by:
Hi, I'm trying to delete a whole bunch of records and keep getting the message "File Sharing Lock Count Exceeded (Error 3052)". What is this error and how do I overcome it? Thanks guys.
3
by: R.A. | last post by:
Hi I have the web pages developed using c#. When I change the http to https the lock showing the secure site is not showing. Is there more beside changing the http to https to convert the web...
3
by: Bryan Shaw | last post by:
I do not want my users to be able to copy and paiste anything on these web pages, which will be on an internal web site. Is there a way to prevent the printing of a web page? Is there a way to...
14
by: Gary Nelson | last post by:
Anyone have any idea why this code does not work? FileOpen(1, "c:\JUNK\MYTEST.TXT", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Shared) Dim X As Integer For X = 1 To 26 FilePut(1, Chr(X +...
4
by: David Veeneman | last post by:
Is there any way to forcibly release a lock on a text file, so that it can be deleted? I am testing an order-processing site that saves transaction information in a text file that it attaches to...
5
by: pgdown | last post by:
Hi, I have several processes accessing files from one folder, but only one process should ever access each file. Once one process has the file, no other process should be allowed to access it,...
2
by: WingSiu | last post by:
I am writing a Logging util for my ASP.NET application. I am facing mulit process problem. I developed a class LogFactory, and have a method called Get_Logger to create a FileLogger, which will...
1
by: graphicguru | last post by:
Hi i got some javascript from (*) these site for lock one column with js and header row with css. i am not a programmer i am a designer. i am working in a small company. i don't find such...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.