sftp协议通过调用libcurl库实现文件的上传
来源:互联网 发布:java塔防游戏 编辑:程序博客网 时间:2024/04/30 02:37
#include <stdio.h>
#include <stdlib.h>
size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) //回调函数
{
curl_off_t nread;
size_t retcode = fread(ptr, size, nmemb, (FILE*)(stream));
nread = (curl_off_t)retcode;
return retcode;
}
int main(void)
{
CURL *curl;
CURLcode res;
const char* urlkey = "用户名:密码"; //服务器用户名密码
FILE* pSendFile = fopen("本地文件路径", "rb");
fseek(pSendFile, 0L, SEEK_END);
size_t iFileSize = ftell(pSendFile);
fseek(pSendFile, 0L, SEEK_SET);
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL,
"sftp://服务器IP地址/服务器端的文件路径");
curl_easy_setopt(curl, CURLOPT_USERPWD,urlkey);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, pSendFile);
curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 0);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, iFileSize);
#ifndef DISABLE_SSH_AGENT
curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PASSWORD);
#endif
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
}
curl_global_cleanup();
return 0;
}
#include <stdlib.h>
#include <curl.h>
size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) //回调函数
{
curl_off_t nread;
size_t retcode = fread(ptr, size, nmemb, (FILE*)(stream));
nread = (curl_off_t)retcode;
return retcode;
}
int main(void)
{
CURL *curl;
CURLcode res;
const char* urlkey = "用户名:密码"; //服务器用户名密码
FILE* pSendFile = fopen("本地文件路径", "rb");
fseek(pSendFile, 0L, SEEK_END);
size_t iFileSize = ftell(pSendFile);
fseek(pSendFile, 0L, SEEK_SET);
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL,
"sftp://服务器IP地址/服务器端的文件路径");
curl_easy_setopt(curl, CURLOPT_USERPWD,urlkey);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, pSendFile);
curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 0);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, iFileSize);
#ifndef DISABLE_SSH_AGENT
curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PASSWORD);
#endif
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(CURLE_OK != res)
{
fprintf(stderr, "curl told us %d\n", res);}
}
curl_global_cleanup();
return 0;
}
阅读全文
0 0
- sftp协议通过调用libcurl库实现文件的上传
- php 通过ssh2协议用sftp实现文件上传、下载
- 支持sftp协议的libcurl编译
- libCurl 库sftp上传和下载
- java上传文件通过SFTP
- 通过SHELL脚本实现SFTP文件自动上传与下载
- libCurl的文件上传
- 通过Http协议实现文件上传
- 通过Http协议实现文件上传
- android通过http协议实现文件上传
- 通过HTTP协议实现文件上传
- sftp通过秘钥上传,修改文件
- (1) java通过sftp上传文件
- JSch - Java实现的SFTP(文件上传详解篇)
- JSch - Java实现的SFTP(文件上传详解篇)
- JSch - Java实现的SFTP(文件上传详解篇)
- JSch - Java实现的SFTP(文件上传详解篇)
- JSch - Java实现的SFTP(文件上传详解篇)
- TCP IP协议之初识
- 【设计模式】简介
- WARN No appenders could be found for logger的解决方法
- 云创-数据需求拉取-geyuan
- 斐波那契数列三种实现方式
- sftp协议通过调用libcurl库实现文件的上传
- 自定ViewPager 切换效果,PageTransformer这个类实现
- Eclipse 配置tom-cat7 报错处理方法
- 各大视频网站会员低价激活码。直冲自己账户。
- Java中清除session
- 图像缩放--OpenCV cvResize函数--最近邻插值---双线性插值--基本原理
- c#委托引用与取消引用注意事项
- SEO关键词优化
- mysql 5.7以上版本命令行安装配置