2

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

or

  • 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.

4

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.

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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