cURL / Mailing Lists / curl-library / Single Mail


sftp upload - curl error 79 Error in the ssh layer

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

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/ -u user:password sftp://fabrika/tmp/

calling curl with following code

struct stat file_info;
FILE *fd = fopen(f:/temp/,"rb");
int res_st = fstat(fileno(fd), &file_info);
fclose(fd);,ios::in | ios::binary);

CURL *h_curl;
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_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
Connected to fabrika ( port 22 (#0)
SSH MD5 fingerprint: 9e73dade666cbbac9a82adfeffbd9f18
SSH authentication methods available: publickey,password
Using ssh public key file
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.

List admin:
Received on 2014-03-20