Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to write a script that runs on a server and looks for a configuration file every x seconds and starts or kills other scripts depending on the data in the configuration file. My question now is: When somebody uploads this configuration file via ftp could it be that my script just gets a part of this configuration data if the upload is not jet finished. How can I ensure that I never get a broken (= not yet complete uploaded) configuration file?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

It may well be possible to get a broken file, especially if they're quite large. If they're really small (a few lines) it's not very likely. You have to think about what happens if you read it while a new one is being uploaded, or if something interrupts the upload.

One way of dealing with this kind of thing is to upload the file to a temporary name, then rename it to replace the real one. That way the real one is never incomplete.

While you can do this from the client, it's a bit inconvenient if the uploads are manual. (great if they're automatic though).

Quite a few FTP servers will take care of this for you, though.

For example ProFTPD has the configuration option HiddenStores:

http://www.proftpd.org/docs/directives/linked/config_ref_HiddenStores.html

NcFTPd has something similar:

http://www.ncftp.com/ncftpd/doc/config/g/upload-tmp-then-rename.html

Have a look through the manual for whichever FTP server you're using.

share|improve this answer
    
Thank you. As I read your I had the idea to ensure that the data is complete by storing the data in a format that could only be read if it is complete: I will store the configuration in json, so it won't be a problem. –  stofl Oct 20 '11 at 10:02
    
that's an interesting idea, I don't see why it wouldn't work. –  Colin Coghill Oct 20 '11 at 20:27
add comment

Take a look at mod_digest for ProFTPD.

share|improve this answer
    
How could this help me? I think it would be easier to use the hooks of the ftp server to run the script after the upload of the configuration file is finished. But I first would like to know if it is possible to get a broken file and how I can prevent this. –  stofl Oct 19 '11 at 17:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.