#include <curl/curl.h>

#undef DISABLE_SSH_AGENT

struct FtpFile {
const char *filename;
FILE *stream;
}; static size_t my_fwrite(void *buffer, size_t size, size_t nmemb,
void *stream)
{
struct FtpFile *out = (struct FtpFile *)stream;
if(!out->stream) {
/* open file for writing */
out->stream = fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, can't open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
} //sftp协议
void fileLoadSftp()
{
CURL *curl;
CURLcode res; char *filename = ui->lineEdit_path->text().toLatin1().data(); //本地文件名
QString remote = "sftp://user:password@example.com/etc/issue";
char *remote_url = remote.toLatin1().data(); //服务器路径 struct FtpFile ftpfile =
{
filename, /* name to store the file as if successful */
NULL
}; curl_global_init(CURL_GLOBAL_DEFAULT); curl = curl_easy_init();
if(curl) {
/*
* You better replace the URL with one that works!
* sftp://user:password@example.com/etc/issue - This specifies the file /etc/issue
*/
curl_easy_setopt(curl, CURLOPT_URL, remote_url);
/* Define our callback to get called when there's data to be written */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
/* Set a pointer to our struct to pass to the callback */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); #ifndef DISABLE_SSH_AGENT
/* We activate ssh agent. For this to work you need
to have ssh-agent running (type set | grep SSH_AGENT to check) or
pageant on Windows (there is an icon in systray if so) */
curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PASSWORD);
#endif /* Switch on full protocol/debug output */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); /* always cleanup */
curl_easy_cleanup(curl); if(CURLE_OK != res) {
/* we failed */
fprintf(stderr, "curl told us %d\n", res);
}
} if(ftpfile.stream)
fclose(ftpfile.stream); /* close the local file */ curl_global_cleanup();
}

curl sftp libcurl 功能使用的更多相关文章

  1. curl ftp libcurl 功能使用

    struct FtpFile { const char *filename; FILE *stream; }; static size_t my_fwrite(void *buffer, size_t ...

  2. curl http libcurl 功能使用

    /* * This example shows a HTTP PUT operation. PUTs a file given as a command * line argument to the ...

  3. curl tftp libcurl 功能使用

    #include <curl/curl.h> static size_t read_callback(void *ptr, size_t size, size_t nmemb, void ...

  4. cURL 是一个功能强大的PHP库。

    使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了.无论是你想从从一个链接上取部分数据,或是取一个XML文件并把 ...

  5. curl smtp libcurl 邮件功能使用

    /* * For an SMTP example using the multi interface please see smtp-multi.c. */ /* The libcurl option ...

  6. CURL 和LIBCURL C++代码 上传本地文件,好不容易碰到了这种折腾我几天的代码

    解决了什么问题:curl在使用各种方式上传文件到服务器.一般的文件上传是通过html表单进行的,通过CURL可以不经过浏览器,直接在服务器端模拟进行表单提交,完成POST数据.文件上传等功能. 服务器 ...

  7. 海思平台交叉编译curl支持SSL功能

    1.准备工具 1).交叉编译工具 2).下载libcurl和openssl源代码,我使用的是(openssl-1.0.2o.tar,curl-7.59.0.tar) 3).查看cpu详细 ~ # ca ...

  8. Java 通过SFTP上传图片功能

    1.需要在pom.xml文件中引用jsch的依赖: <dependency> <groupId>com.jcraft</groupId> <artifactI ...

  9. linux下不同服务器间数据传输(rcp,scp,rsync,ftp,sftp,lftp,wget,curl)(zz)

    linux下不同服务器间数据传输(rcp,scp,rsync,ftp,sftp,lftp,wget,curl) 分类: linux2011-10-10 13:21 8773人阅读 评论(1) 收藏 举 ...

随机推荐

  1. 5.JavaCC官方入门指南-概述

    一.前言   在最开始使用JavaCC的时候,从网上查询了许多资料,但是网上的资料水平是参差不齐的,走了许多弯路,不得已自己查阅了英文版官网文档.令我伤心的是最后我回过头来再看那些博客资料时,发现其实 ...

  2. 【mysql】pymysql.err.InterfaceError Interface Error: (0, '')

    八成是丢失连接了 while 1: try: self.conn.ping(reconnect=True) self.cur.execute(sql,tuple(item.values())) sel ...

  3. Python创建virtualenv虚拟环境方法

    一.通过virtualenv软件创建 安装:        -pip3 install virtualenv    创建虚拟环境:        -(1)virtualenv wannings-ms- ...

  4. Python—时间模块(time)和随机模块(random)

    时间模块 time模块 获取秒级时间戳.毫秒级时间戳.微秒级时间戳 import time t = time.time() print t # 原始时间数据 1574502460.90 print i ...

  5. 查找树ADT--二叉查找树

    二叉树的一个重要应用是它们在查找中的使用. 二叉查找树的性质:对于树中的每个节点X,它的左子树中所有项的值小于X中的项,而它的右子树中所有项的值大于X中的项.这意味着该树所有的元素可以用某种一致的方式 ...

  6. [PHP] 安装PHP报错“Primary script unknown”的解决方法

    当安装完最新版的nginx和最新版的PHP以后,使用niginx默认配置文件中的PHP配置会有错误访问指定目录下的php文件时,显示File not found.错误.查看nginx的错误日志显示 9 ...

  7. Eclipse修改JSP文件的默认编码

    Eclipse新建JSP文件,可以看到默认使用的是ISO-8859-1编码,如下图,而这种编码是无法保存中文的,不符合我们的需求 那么应该怎样修改呢?找到菜单Window-Preferences,找到 ...

  8. postman---postman简单介绍

    有小伙伴们想要了解postman,今天它来了,不要问它到底有多强大,自古免费好用即是王道,它不仅仅是开发接口强大的调试工具,还是测试接口的居家必备,它不仅仅可以把需要调用的接口保存下来方便调用,还可以 ...

  9. (六)Amazon Lightsail 部署LAMP应用程序之升级到Amazon EC2

    升级到Amazon EC2 将Amazon Lightsail实例升级为Amazon EC2 您将进行以下操作: ①创建使用 Amazon RDS的Web前端实例的快照 ②将该快照导出到 Amazon ...

  10. 19.Java基础_封装概念