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.

Typically I upload updated files/scripts over Secure FTP to my server to replace existing copies of those files as I make changes. But this has the nasty behavior of writing directly to those files. This means that while the files are being uploaded, those files/scripts will be broken (due to being incomplete) for anyone who loads the web site during that time. How can I fix this?

I assumed the secure FTP/SSH daemon would be smart enough to keep in-progress downloads in a temporary location (like /tmp) until the transfer is complete, and then quickly copy the files to the intended location. Is there an easy way to make it do something like that?

Thanks!

share|improve this question
add comment

2 Answers

On a per-file basis, rsync has this behaviour, so I'd recommend using that (for all sorts of other reasons, too). If you need to atomically swap out your entire site, then Josh's answer is the way to go.

share|improve this answer
    
Funny how your answer was basically, "Josh's answer is correct", yet you get more upvotes ;-) -- I didn't know that rsync had the behavior you described. I know pure-ftpd does. Do you know about sftp? –  Josh Nov 9 '09 at 17:48
    
@Josh: I don't see any mention of rsync in your answer. –  womble Nov 9 '09 at 19:09
    
Ok. I misread your answer. I thought he was asking only about swapping entire directories, not individual files. Sorry! :-) –  Josh Nov 10 '09 at 0:58
add comment

(S)FTP everything to a temporary directory. Upon completion, rename the destination directory and rename the temporary directory to take it's place.

For example, let's say you're uploading everything to public_html:

  1. Via SFTP make a new directory public_html_new at the same level as public_html

  2. Upload everything to public_html_new

  3. When the upoad finishes, rename public_html to public_html_old, and the rename public_html_new to public_html

share|improve this answer
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.