SFTP/SCP Atomic Copy

I’ve come across Mihai Secasiu’s very useful patch for OpenSSH, that enables SCP and SFTP to do atomic copying.

We needed that functionality on one of our servers, so I decided to give it a try. However, we were using OpenSSH 5.3p1 instead of 4.6 (the version the patch was made for) and the patch didn’t apply completely.

After a couple of tweaks, I’ve managed to make it apply on 5.3p1 and, in the same Open Source spirit shown by the original patch author’s , here’s my modified version that applies against 5.3p1:

openssh_scp_sftp_atomic-5.3p1

Check the original patch post on PatchLog for instructions about how to build it and configure. There’s a lot more nice stuff on the site as well.

Nice job Mihai! 🙂

Alex

Comments (4)

PaulFebruary 11th, 2010 at 5:48 AM

This patch doesn’t seem to handle file uploads properly.

With small uploads:
The temp directory is used correctly and the file is uploaded and then moved to the destination directory but one ends up with a zero size file in the temp directory and any command following the upload fails and the ssh connection is terminated.

With large uploads:
The temp directory is used correctly and the file is uploaded and then moved to the destination directory but any command following the upload fails and the ssh connection is terminated.

I suspect it’s some file handling issue.

PaulFebruary 12th, 2010 at 6:44 AM

At line 607 in sftp-server.c I added “orginame = NULL”
Thus the code looks like this:
607: xfree(origname);
608: origname = NULL;

The origname isn’t set to NULL on the xfree and thus a command such as “ls” following a file upload would generate an error because it would enter the code block that is only supposed to be used for a file upload.

The atomic upload works fine for the default Linux sftp client but breaks clients such as WinSCP (running in SFTP mode). WinSCP seems to do some sort of operation on the file while it is being uploaded but since it only exists in a temp directory it can’t find the file and spits out errors.

alexFebruary 12th, 2010 at 8:39 AM

Paul, if I understand correctly with the changes you’ve made now it would work fine on Linux but still fail on WinSCP? Let me know and I’ll update the patch.

Pauls ftp storageAugust 29th, 2010 at 10:21 AM

Now we need a patch to patch the patch because this is no longer uploading properly for me on large files!