【问题标题】:curl error - 79 Error in the ssh layercurl 错误 - 79 ssh 层中的错误
【发布时间】:2014-04-25 18:42:58
【问题描述】:

我在 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 使用的一些参数,如果有任何建议,我将不胜感激。

彼得

【问题讨论】:

    标签: c++ curl ssh


    【解决方案1】:

    您的应用程序似乎无权读取“id_dsa.pub”,因此 SSH 握手未完成。 尝试查看 CURLOPT_CAINFO

    【讨论】:

    • 我需要提供那个来卷曲吗?我理解它有两种身份验证方法,密钥和用户/密码,密钥失败,而用户/密码成功。还引用手册页“如果 CURLOPT_SSL_VERIFYPEER 为零,则 CURLOPT_CAINFO 甚至不需要指示可访问文件”
    • 尝试查看 CURLPROTO_SFTP
    【解决方案2】:

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

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

    成功了。

    【讨论】:

    • 一个额外的隐藏技巧。如果您不知道 SFTP 服务器上的当前用户路径,Curl 接受字符 '~' 作为“HOME”变量。因此,您可以使用sftp://fabrika/~/openvpn-config.zip 直接将文件复制到您的 SFTP 用户的路径
    • 对于其他因 curl 错误来到这里的人 curl: (79) Upload failed: Operation failed (4/-31)。这可能意味着您要放置数据的 SFTP 上没有足够的空间。从 SFTP 中删除旧的和不必要的文件解决了我的问题。
    猜你喜欢
    • 2018-10-06
    • 1970-01-01
    • 2012-04-30
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    相关资源
    最近更新 更多