Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl error - 79 Error in the ssh layer

Tags:

c++

curl

ssh

I am using curl library within c++ code. I would like to upload a file to the server using sftp and user authentization. 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 options

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_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");

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.

Edit: Forgot to add debug information from verbose mode, here it is

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.

Petr

like image 506
user3437734 Avatar asked Feb 14 '23 11:02

user3437734


1 Answers

Answer: I got an answer via curl mailing-list, so here it is in case someone got stuck like me. When uploading files, curl needs full target path, including filename. So

curl_easy_setopt(h_curl, CURLOPT_URL, "sftp://fabrika/tmp/openvpn-config.zip");

did the trick.

like image 167
user3437734 Avatar answered Feb 16 '23 02:02

user3437734