使用SFTP在C中使用libcurl下载文件:c中为“不受支持的协议”,但命令行有效

问题描述

我的代码基于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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...