cURL / Mailing Lists / curl-library / Single Mail


Re: sftp postquote command rename fix/diff question

From: Dan Fandrich <>
Date: Wed, 9 May 2007 16:11:32 -0700

On Thu, May 10, 2007 at 12:24:22AM +0200, Kristian Gunstone wrote:
> This patch has modifications to the rename and rm handlers in lib/ssh.c.
> As tipped, I'm now just returning an error if rename fails due to
> destination already existing.
> In order to test this, I also had to make modifications to the file
> delete handler at the same time, since it also returns an unknown error
> to the user application if the file does _not_ exist, and thus I added
> support for this return code at the same time.
> Seems to work properly now, but it sure makes renaming slow for user
> applications since the entire connection has to be reestablished between
> rename, delete, and reattempt to rename (that's how it is right now for
> sftp it seems)

That does seem like an annoying limitation. Can't you simply look at the
error code returned by sftp_libssh2_strerror after a failed
libssh2_sftp_rename? Doesn't that provide a sane error status of some sort?
Failing that, how about just doing the stat call after the rename fails
instead of before?

In any case, calling libssh2_sftp_stat in this way opens up a race condition;
even if stat shows no file exists, a process on the server might create
the file before the rename can be executed and it will *still* return an

> Well, hope you prefer this method.

Not quite sure I do...

>>> Dan

--              The web change of address service
          Let webmasters know that your web site has moved
Received on 2007-05-10