cURL / Mailing Lists / curl-library / Single Mail

curl-library

sftp upload - curl error 79 Error in the ssh layer

From: Petr Ent <petr.ent_at_gmail.com>
Date: Thu, 20 Mar 2014 09:12:23 +0100

Hello,
I am using curl library within c++ code. I use C++ Builder XE2, curl
as .dll and .lib extracted from .dll by implib. I would like to upload
a file to the server using sftp and user authentication. While I
manage to do this from windows command line using

curl -k -T f:/temp/openvpn-config.zip -u user:password sftp://fabrika/tmp/

calling curl with following code

struct stat file_info;
FILE *fd = fopen(f:/temp/openvpn-config.zip,"rb");
int res_st = fstat(fileno(fd), &file_info);
fclose(fd);

ffile.open(f:/temp/openvpn-config.zip,ios::in | ios::binary);

CURL *h_curl;
curl_global_init(CURL_GLOBAL_ALL);
h_curl = curl_easy_init();
curl_easy_setopt(h_curl, CURLOPT_URL, "sftp://fabrika/tmp/");
curl_easy_setopt(h_curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(h_curl, CURLOPT_READDATA, (void*)&ffile);
curl_easy_setopt(h_curl, CURLOPT_READFUNCTION, &ReadCallback);
curl_easy_setopt(h_curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
curl_easy_setopt(h_curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(h_curl, CURLOPT_USERPWD, "user:password");
CURLcode res = curl_easy_perform(h_curl);

gives me error code 79, which tranlates into "Error in the ssh layer".
I checked the fstat result, the file size passed to curl is correct.
After enabling verbose mode, I got following output

Hostname was NOT found in DNS cache
Adding handle: conn: 0x4236ef0
Adding handle: send: 0
Adding handle: recv: 0
Curl_addHandleToPipeline: length: 1
- Conn 0 (0x4236ef0) send_pipe: 1, recv_pipe: 0
Trying 192.168.3.1...
Connected to fabrika (192.168.3.1) port 22 (#0)
SSH MD5 fingerprint: 9e73dade666cbbac9a82adfeffbd9f18
SSH authentication methods available: publickey,password
Using ssh public key file id_dsa.pub
Using ssh private key file id_dsa
SSH public key authentication failed: Unable to open public key file
Initialized password authentication
Authentication complete
Upload failed: Operation failed (4/-31)
Connection #0 to host fabrika left intact

Clearly I am missing some parameter used by the command line curl
which does the trick, I'll be grateful for any suggestions.

thanks
Petr
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-03-20