curl sftp libcurl 功能使用
#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 功能使用的更多相关文章
- curl ftp libcurl 功能使用
struct FtpFile { const char *filename; FILE *stream; }; static size_t my_fwrite(void *buffer, size_t ...
- curl http libcurl 功能使用
/* * This example shows a HTTP PUT operation. PUTs a file given as a command * line argument to the ...
- curl tftp libcurl 功能使用
#include <curl/curl.h> static size_t read_callback(void *ptr, size_t size, size_t nmemb, void ...
- cURL 是一个功能强大的PHP库。
使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了.无论是你想从从一个链接上取部分数据,或是取一个XML文件并把 ...
- curl smtp libcurl 邮件功能使用
/* * For an SMTP example using the multi interface please see smtp-multi.c. */ /* The libcurl option ...
- CURL 和LIBCURL C++代码 上传本地文件,好不容易碰到了这种折腾我几天的代码
解决了什么问题:curl在使用各种方式上传文件到服务器.一般的文件上传是通过html表单进行的,通过CURL可以不经过浏览器,直接在服务器端模拟进行表单提交,完成POST数据.文件上传等功能. 服务器 ...
- 海思平台交叉编译curl支持SSL功能
1.准备工具 1).交叉编译工具 2).下载libcurl和openssl源代码,我使用的是(openssl-1.0.2o.tar,curl-7.59.0.tar) 3).查看cpu详细 ~ # ca ...
- Java 通过SFTP上传图片功能
1.需要在pom.xml文件中引用jsch的依赖: <dependency> <groupId>com.jcraft</groupId> <artifactI ...
- 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) 收藏 举 ...
随机推荐
- SoapUI、Postman测试WebService
之前装了SoapUI,最近装了Postman,分别用它们测试了WebService,下面为用法. 测试的在线WebService(数据来源于中国气象局)Endpoint: http://www.web ...
- 记录TortoiseGit=>https请求/ssh请求配置
ssh C:\Program Files\Git\usr\bin\ssh.exe https C:\Program Files\TortoiseGit\bin\TortoisePlink.exe
- bay——安装_RAC11g_LC_ASM方式_测试环境.txt
★★★____★☆★〓〓〓〓→VMware vSphere Client6.0 https://10.20.4.200/ 下载Vwmare IP:10.20.4.200-------账号:root-- ...
- docker介绍和安装(一)
虚拟化简介 虚拟化(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源,如服务器.网络.内存及存储等,予以抽象.转换后呈现出来,打破实体结构间的不可切割的障碍,使用户可以 ...
- 25.Java基础_继承
继承的格式(Java类) Java中继承的注意事项 继承的好处与弊端 继承中成员变量的访问特点(对public形式的变量来说) 继承中成员函数的访问特点 this和super: 继承中构造方法的访问特 ...
- luoguP1447 [NOI2010]能量采集
https://www.luogu.org/record/22874213 题目大意:给定n和m,求Σ(1<=i<=n)Σ(1<=j<=m)GCD(i,j)* 2-1 i和j的 ...
- pycharm 快速启动Django项目和python程序
Django 设置 *.py
- Spring配置文件中的那些标签
1. context:annotation-config 它的作用是隐式地向Spring容器注册AutowiredAnnotationBeanPostProcessor,CommonAnnotatio ...
- ILRuntime 学习
ILRuntime: https://github.com/Ourpalm/ILRuntime Demo: https://github.com/Ourpalm/ILRuntimeU3D 中文在线文档 ...
- Note | Ubuntu18.04安装与配置
目标: 在服务器上配置最新的Ubuntu稳定版本18.04 LTS.18.04比16.04好看很多,非常建议. 有3块硬盘:2块4TB机械硬盘,1块2TB固态硬盘.计划将固态硬盘作为主硬盘,其余两块机 ...