cURL / Mailing Lists / curl-library / Single Mail

curl-library

a question regarding SFTP using curl

From: Zhonggui Li <zhongguili_at_gmail.com>
Date: Mon, 6 Apr 2009 14:53:55 +0200

Hi,

I am using Curl to upload file with SFTP under: SunOS 5.9. Curl version is
as follows:

$ curl --version
curl 7.17.1 (sparc-sun-solaris2.9) libcurl/7.17.1 OpenSSL/0.9.8 zlib/1.2.3
libssh2/0.18
Protocols: tftp ftp telnet dict ldap http file https ftps scp sftp
Features: IPv6 Largefile NTLM SSL libz

$ curl-config --libs
-L/develop/lib -lcurl -L/develop/lib -L/develop/lib -L/develop/lib -lssh2
-lssl -lcrypto -lldap -lsocket -lnsl -lz
When I tried with Command line, I managed to upload files to the server. So
the key files are working.

 However when I did it in C, I received the following
information (error occurs when performing curl_easy_perform with an error
code of 2):

* About to connect() to *.*.*.* port 22 (#0)
* Trying *.*.*.*... * connected
* Connected to *.*.*.* (*.*.*.*) port 22 (#0)
* Failure establishing ssh session
* Closing connection #0
* Failed initialization

When I dig into the error code, it says something like "set the port to be
non-blaocking while the call may block"....
Thank you in advance if you can offer a hint..

The code looks something like:

  lp_curl = curl_easy_init();
  curl_easy_setopt(lp_curl, CURLOPT_UPLOAD, GC_TRUE);
  curl_easy_setopt(lp_curl, CURLOPT_VERBOSE, 1);

  snprintf(userpass, GC_SIZE_USRPASS, "%s:%s", user, password);
  curl_easy_setopt(lp_curl, CURLOPT_USERPWD, userpass);

  snprintf(url, GC_SIZE_URL, "%s://%s%s/%s", protocol,
           server, path ,filename);
  curl_easy_setopt(lp_curl, CURLOPT_URL, url);

  curl_easy_setopt(lp_curl, CURLOPT_SSH_AUTH_TYPES,
                      CURLSSH_AUTH_PUBLICKEY);
  curl_easy_setopt(lp_curl, CURLOPT_SSH_PRIVATE_KEYFILE, prikeyfile);
  curl_easy_setopt(lp_curl, CURLOPT_SSH_PUBLIC_KEYFILE, pubkeyfile);

  curl_easy_setopt(lp_curl, CURLOPT_READDATA, file);
  curl_easy_setopt(lp_curl, CURLOPT_READFUNCTION, upcall); //callback
function: upcall

  status = curl_easy_perform(lp_curl);
Received on 2009-04-06