1

I have to regularly update a file on a server using SFTP transfer and libcurl. From many sources and personal experience I discovered that rename command using curl with SFTP fails when the destination path points to already existing file. But sftp client does not work that way - the same command overwrites the existing file. Isn't there really way to force this behaviour on libcurl. I am aware of the option of deleting the file first, but then comes the problem that it fails if the file doesn't exists and it is still a workaround rather than a solution to me.

Edit: libcurl raises the LIBSSH2_SFTP_RENAME_OVERWRITE flag of libssh2_sftp_rename_ex but it seems to not work for some versions of the protocol/server

Workaround: add commands "*rm" which points that rm can fail

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222

1 Answers1

1

I'm pretty sure the reason is that in the case when curl fails to rename a file over SFTP, it is because the server denies it. We've seen it happens at times by some servers even though curl sends the "force overwrite" option.

The reason other clients may work can be that they do rm + mv under the hood or perhaps because they negotiate a different SFTP protocol version with the server (and thus get different behavior).

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222