Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question

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

(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

Your Answer


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.