#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. 记一次接口调试错误: {"timestamp":"2019-09-11T03:04:30.036+0000","status":500,"error":"Internal Server Error","message":"Could not write JSON: Object is null; nested exception is com.fasterxml.jackson

    接口测试中用postman测试返回是正常的,但是使用其他人去调用就出错了,找了半天,才想起来使用了nginx,用于端口的代理转发.然后根据错误信息发现json格式的某个字段为null,结合日志中的报文 ...

  2. express 将 Router 实例模块化

    为了更好的组织代码,将 Router 实例进行模块化,将 get / post 等快捷方式放在Router上,而不是 App 上,然后将该 Router 作为中间件,use 到 server.js 上 ...

  3. JavaScript—图片与base64编码互相转换

    图片转换为base64编码 <input type = "file" id = "file" onchange="popFileName(thi ...

  4. easyui三

    陈旧的开发模式 美工(ui工程师:出一个项目模型) java工程师:将原有的html转成jsp,动态展示数据 缺点: 客户需要调节前端的展示效果 解决:由美工去重新排版,重新选色.Vs前后端分离 美工 ...

  5. Pwnable-random

    ssh连接,输入密码查看目录下的文件 看看random.c的源码 #include <stdio.h> int main(){ unsigned int random; random = ...

  6. 【转】HTTPS建立连接的过程

    原文链接:https://www.cnblogs.com/shiqi17/p/9756880.html https://www.jianshu.com/p/bd75ab32ae57 HTTP建立连接的 ...

  7. [C1W1] Neural Networks and Deep Learning - Introduction to Deep Learning

    第一周:深度学习引言(Introduction to Deep Learning) 欢迎(Welcome) 深度学习改变了传统互联网业务,例如如网络搜索和广告.但是深度学习同时也使得许多新产品和企业以 ...

  8. 《高性能MySQL》读后感——聚簇索引

    <高性能MySQL>读后感——聚簇索引 聚簇索引并不是一种单独的索引类型,而是一种数据存储方式.比如,InnoDB的聚簇索引使用B+Tree的数据结构存储索引和数据. 当表有聚簇索引时,它 ...

  9. SCOI 2005 互不侵犯

    洛谷 P1896 [SCOI2005]互不侵犯 洛谷传送门 题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一 ...

  10. Go micro 入门

    路由跳转 官方文档 本质上是选择不同的方式将HTTP信息合理的转发至后端处理,而不同的方式相当于不同请求的接收器,接收后再将其转发至不同的后端服务,完成整个请求的调用. micro 将请求选择不同的方 ...