curl-library
Re: libcurl SFTP file upload
Date: Fri, 4 Apr 2008 13:31:09 +0200 (CEST)
On Fri, 4 Apr 2008, Mueller, Alexander wrote:
> after 2 days of experimenting with curl, hoping to be able to upload a file
> via SFTP, today I gave up and just wanted to post my experiences for others
> trying the same. Hopefully no one else uses 2 days time for this again and
> also fails.
You're of course free to do as you please, but in my view you seem to have
tripped just a few inches from your goal and that's a weird point to give up -
in my view.
> In order to get SFTP going, you'll have to download OpenSSL package
> separately (this is not contained in libcurl, don't ask me why)
It is separate because it is a separate project with a separate license.
> then download libssh2 package (also not contained).
Same goes for that.
> Comment this out: curl_easy_setopt(hCurl, CURLOPT_UPLOAD, 1) ;
> otherwise you'll also get an error after connecting to the server
Can you elaborate on this? Comment this out from what? Ie can you show us a
full example where this causes problems?
> successfully, but this won't work (of cource the subfolder exists):
>
> curl_easy_setopt(hCurl, CURLOPT_URL, "sftp://mydomain.de/subfolder");
While you may be tricked into believing that's a fine URL, it isn't. SFTP and
SCP URLs are crafted differently and then no, you probably did not have those
directories. An SFTP URL for the local directory "subfolder" would look like:
"sftp://mydomain.de/~/subfolder/"
> Then, when trying to use the "cd" command in libcurl, libcurl goes into an
> endless loop, this seems to be the case with all SFTP commands that are not
> supported in libcurl. The same goes for "put".
The infinite loop thing for unknown commands is a bug that we recently fixed.
The recognized and working commands are listed in the manual: chgrp, chmod,
chown, ln, mkdir, pwd, rename, rm, rmdir, symlink.
put as in upload is not supposed to be done with a "quote" command, but with a
regular libcurl CURLOPT_UPLOAD approach.
> But the documentation lists SFTP in the features list, and there is no hint
> that SFTP uploads aren't possible.
That's because they are most certainly possible and even working on most
platforms. We even have several such test cases in the test suite that prove
this.
> There is also no code example for uploading per SFTP, so now I know why.
?
> But there should be somewhere a statment about this, and I hope that my post
> may help others in deciding if they want to try this or not
Yes indeed. And I think my feedback on this can help too.
-- Commercial curl and libcurl Technical Support: http://haxx.se/curl.htmlReceived on 2008-04-04