Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

For example I have some http static server. I'm working with .js files via sftp. Keeping them sync. I'm wondering if .js file is replaced instantly or if the stfp server will write into that file as a stream?

So for example:

  • client started uploading file
  • read stream opened
  • server accept that request
  • open write stream into file location
  • chunks sending to the server
  • chunks accepted and piping into write stream
  • http static server is trying to access file which is not yet uploaded completely and pick partially uploaded file?
  • the result = js errors on the web page


  • sftp load the whole file into the memory
  • then dump whole file from memory into the file

This is the best scenario for me.

Haven't time to check how it's working. Any explanation would be good.

share|improve this question
up vote 3 down vote accepted

scp and sftp will replace the file in-place, so yes, theoretically an HTTP client could try to fetch a partially-uploaded file.

You can mitigate this by using rsync over SSH instead of sftp as this will write to a temporary file first and then replace the file. rsync can also be configured to backup any files it replaces.

share|improve this answer

It is not a protocol feature. SFTP (as a subprotocol/subsystem of SSH) doesn't decide whether to overwrite your files in-place or through a temporary file, the server only performs the commands that are sent in by the client. So this entire matter should be seen from a client-side perspective.

Now, this said, and keeping the above in mind, depending on the client you choose to upload your .js files, you will have a different behavior:

  • sftp will simply upload and overwrite your files in-place
  • rsync over SSH can upload files with temporary names and then delete the old file and rename the newly uploaded one (better option)
  • In the Windows world there's a plethora of SFTP clients that can upload using temporary names and delete/overwrite, probably the most common and well-known of them is WinSCP
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.