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) 收藏 举 ...
随机推荐
- [20190524]浅谈模糊查询.txt
[20190524]浅谈模糊查询.txt --//一台生产系统遇到监听进程莫名down的情况,3月份曾经遇到的情况,链接:http://blog.itpub.net/267265/viewspace- ...
- 告诉你一些DBA求职面试技巧
告诉你一些DBA求职面试技巧 要自信!永远不要低估你的能力.如果你不了解什么问题的答案,承认它.重点放在你找出答案的能力和你学习的意愿. 不要自大!是的,你可能过于自信而被认为是骄傲的.轻率的,甚至是 ...
- Tangent element-Vs虚拟调色台安装配置
iPad安装element-Vs 从Tangent网站下载Element-Vs的Tangent Hub程序安装 确保系统防火墙允许对Tangent Hub的网络访问并且与iPad共用一个局域网连接 开 ...
- [C4W1] Convolutional Neural Networks - Foundations of Convolutional Neural Networks
第一周 卷积神经网络(Foundations of Convolutional Neural Networks) 计算机视觉(Computer vision) 计算机视觉是一个飞速发展的一个领域,这多 ...
- win10打印所有进程
#include <map> #include <iostream> #include <string> #include <windows.h> #i ...
- Conda和Python的国内安装源
Conda和Python的国内安装源 Windows系统: 更换python国内源的方法. 在"C:\Users[xxxx]\pip\pip.ini"文件中配置如下内容(没有则新建 ...
- CME Futures & Options Order Book
http://algo-logic.com/futures-options-orderbook Algo-Logic Systems’ Futures & Options (F&O) ...
- Python __slots__
Python 类的特殊变量:__slots__ 使用 __slots__ 后,类中 __weakref__ 和 __dict__ 消失,同时阻止动态属性绑定 由于 __dict__ 记录着类中所有的属 ...
- Note | PyTorch1.2 + CUDA10.0 + cuDNN7.6 + Anaconda3配置
目标: 在2080Ti GPU上,运行PyTorch1.2 GPU版本. 经过确认,PyTorch1.2可以搭配CUDA10.0,而CUDA10.0搭配cuDNN7.6(官网下载页面可以直接看到). ...
- flutter,SliverPersistentHeader实现Tab顶部吸附固定效果
直接上代码啦 import 'package:flutter/material.dart'; class StickyDemo extends StatefulWidget { @override _ ...