问题描述
我的代码基于Download file using libcurl in C/C++,但出现错误: 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;
}
通过curl -V命令进行了检查,该命令支持 SFTP 。 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
有人可以为此提出建议吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)