【发布时间】:2020-08-11 10:19:58
【问题描述】:
我的代码基于Download file using libcurl in C/C++,但我收到一个错误:“不支持的协议” for SFTP。但是,对于相同的 SFTP,文件下载和上传使用命令行。
代码:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
FILE *fp;
CURLcode res;
//char *url = "http://stackoverflow.com";
char *url = "sftp://dheerajr@10.4.1.156/home/dheerajr/temp/download.txt";
char outfilename[FILENAME_MAX] = "temp.txt";
curl = curl_easy_init();
if (curl)
{
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
if(res == CURLE_OK)
printf("Download Successfull\n");
else
printf("ERROR: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
fclose(fp);
}
return 0;
}
使用支持 SFTP 的 curl -V 命令检查。 curl -V 输出:
curl 7.72.0-DEV (x86_64-pc-linux-gnu) libcurl/7.72.0-DEV OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) libssh2/1.8.2 nghttp2/1.30.0 librtmp/2.3
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS HTTP2 HTTPS-proxy IDN IPv6 Largefile libz NTLM NTLM_WB PSL SSL TLS-SRP UnixSockets
谁能为此提出解决方案?
【问题讨论】:
-
您有没有找到解决方案?我也有同样的问题!
-
是的,我发现解决方案需要通过启用不同的选项进行编译
标签: c curl download sftp libcurl