#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. Linux 安装并配置zsh

    1. 安装zsh,配置agnoster主题 1.1 安装zsh $ sudo apt-get install -y zsh 1.2 安装oh-my-zsh $ sh -c "$(curl - ...

  2. python简单面试题

    在这个即将进入金9银10的跳槽季节的时候,肯定需要一波面试题了,安静总结了一些经常遇到的python面试题,让我们一起撸起来. python面试题 1.求出1-100之间的和 # coidng:utf ...

  3. 智能指针类模板(上)——STL中的智能指针

    智能指针类模板智能指针本质上就是一个对象,它可以像原生指针那样来使用. 智能指针的意义-现代C++开发库中最重要的类模板之一-C++中自动内存管理的主要手段-能够在很大程度上避开内存相关的问题 1.内 ...

  4. python多版本共存pip指向问题

    这两天一致被一个问题困扰,电脑里装了anaconda和python3.7,在命令行里输入python,想要python3.7,出现的确实python3.6,或使用pip安装包时,不知道是装在里pyth ...

  5. day6_logging模块

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/7/11 9:12 # @Author : 大坏男孩 # @File : da ...

  6. 20191028 Codeforces Round #534 (Div. 1) - Virtual Participation

    菜是原罪. 英语不好更是原罪. \(\mathrm{A - Grid game}\) 题解 \(4 \times 4\) 的格子,两种放法. 发现这两种在一起时候很讨厌,于是强行拆分这个格子 上面 \ ...

  7. luoguP5283 [十二省联考2019]异或粽子

    题意 类似超级钢琴,找最优解用可持久化trie. code: #include<bits/stdc++.h> using namespace std; #define re registe ...

  8. window.location.href方式提交json数据

    ${ctx}/vehicleFlow/to_vehflow_detail.do?strJson="+encodeURIComponent(json)

  9. backbone 路由传参(可选)

    因为维护公司的老项目而接触到backbone.以前是只闻其名,未见其码. 因为其他项目需要跳转到本项目的某个页面,但是需要UI改变. 考虑的方法是给路由添加一个可选参数.代码如下: 正常路由: rou ...

  10. python-1-基础认识

    前言 将近2020年,python2即将不再更新,但是我们现在的python3也能非常受欢迎的!回顾一下2/3的区别: 1.python2 源码不标准,混乱,重复代码太多, 2.python3 统一 ...