c++ - curl 错误 - ssh 层中的 79 错误

标签 c++ curl ssh

我在 C++ 代码中使用 curl 库。我想使用 sftp 和用户身份验证将文件上传到服务器。虽然我设法使用

从 Windows 命令行执行此操作
curl -k -T f:/temp/openvpn-config.zip -u user:password sftp://fabrika/tmp/

使用选项调用 curl

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

给我错误代码 79,它翻译成“ssh 层错误”。我检查了 fstat 结果,传递给 curl 的文件大小是正确的。

编辑:忘记从详细模式添加调试信息,这里是

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

很明显,我遗漏了命令行 curl 使用的一些参数,它可以解决问题,我将不胜感激任何建议。

彼得

最佳答案

答案: 我通过 curl 邮件列表得到了答案,所以这里是为了防止有人像我一样被卡住。上传文件时,curl 需要完整的目标路径,包括文件名。所以

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

成功了。

关于c++ - curl 错误 - ssh 层中的 79 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22507249/

相关文章:

c++ - 我如何尝试将 Value* 转换为子类?

linux - 链接器无法找到 curl_global_init

python - webpy 记录到单独的日志文件

ANT SSHEXEC 因算法协商失败错误而失败

mysql - 需要使用 delphi 应用程序通过 SSH 隧道进行引导

c++ - 在 C++ 中使用循环进行八进制转换

c++ - 使用定义和变量之间的区别

c++ - 如何为派生类通用地实现复制构造函数?

java - Curl Token 请求到 Spring RestTemplate 转换

python - 警告 : Unable to load SSH config file '/root/.ssh/config' in fabric