cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Possible libssh2_sftp_rename_ex bug?

From: Jonas Schnelli <jonas.schnelli_at_include7.ch>
Date: Thu, 10 Nov 2011 12:32:14 +0100

> On Wed, 9 Nov 2011, Jonas Schnelli wrote:
>
>> When the file (rename destination) exists, i'll always get a "Operation Failed" from sftp_libssh2_strerror. I'm (curl's) using the LIBSSH2_SFTP_RENAME_OVERWRITE flag.
>
> I gave this a quick glance yesterday.
>
> Isn't it so that this bit named LIBSSH2_SFTP_RENAME_OVERWRITE was added to the SFTP protocol later on and that the server you're using (openssh's?) simply doesn't know about it?

I think atomic upload (upload with a tmp filename then perform a renaming to the destination filename afterwards) is in many software projects very important.

So. How can I do a atomic sftp upload?

I now try to do the following:
1. Upload with a temp name
2. Do a postquote rm (remove) of the destination file (remove the "old file")
3. Perform a postquote rename.

But the problem is:
If the "old file" not exists. The rm (remove) cancels the whole postquote chain.

I did a ssh.c / ssh.h patch to ensure that the rm and rename won't cancel the postquote chain. But the patch does not make very much sens and I'm looking for a better option.

So any other ideas how to do a postquote rename (with removing of the old file)?

I'd like to avoid to check in another call if the destination file exists.

Thanks

>
> See http://www.greenend.org.uk/rjk/2007/sftpversions.html for details on version differences in the SFTP protocol.
>
> --
>
> / daniel.haxx.se
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-11-10