#include <curl/curl.h>

static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
curl_off_t nread;
/* in real-world cases, this would probably get this data differently
as this fread() stuff is exactly what the library already would do
by default internally */
size_t retcode = fread(ptr, size, nmemb, (FILE*)stream); nread = (curl_off_t)retcode; fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
" bytes from file\n", nread);
return retcode;
} //tftp协议上传
void fileUploadTftp()
{
CURL *curl;
CURLcode res;
FILE *hd_src;
struct stat file_info;
curl_off_t fsize; QString locale = ui->lineEdit_path->text();
QFileInfo fileInfo(locale);
QString fileName = fileInfo.fileName();
char *locale_file = locale.toLatin1().data(); //本地文件名
QString remote = "tftp://ip:69/" + fileName;
char *remote_url = remote.toLatin1().data(); //服务器路径 struct curl_slist *headerlist; /* get the file size of the local file */
if(stat(locale_file, &file_info)) {
printf("Couldnt open '%s': %s\n", locale_file, strerror(errno));
return;
}
fsize = (curl_off_t)file_info.st_size; printf("Local file size: %" CURL_FORMAT_CURL_OFF_T " bytes.\n", fsize); /* get a FILE * of the same file */
hd_src = fopen(locale_file, "rb"); /* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL); /* get a curl handle */
curl = curl_easy_init();
if(curl)
{
/* we want to use our own read function */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */
curl_easy_setopt(curl,CURLOPT_URL, remote_url); /* pass in that last of FTP commands to run after the transfer */
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist); /* now specify which file to upload */
curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); /* Set the size of the file to upload (optional). If you give a *_LARGE
option you MUST make sure that the type of the passed-in argument is a
curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
make sure that to pass in a type 'long' argument. */
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)fsize); /* Now run off and do what you've been told! */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res)); /* clean up the FTP commands list */
curl_slist_free_all (headerlist); /* always cleanup */
curl_easy_cleanup(curl);
}
fclose(hd_src); /* close the local file */ curl_global_cleanup();
}

curl tftp 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 sftp libcurl 功能使用

    #include <curl/curl.h> #undef DISABLE_SSH_AGENT struct FtpFile { const char *filename; FILE *s ...

  4. windows下实现uboot的tftp下载功能

    一.原理分析 带有uboot的开发板实际上充当的就是tftp客户端,而PC机扮演的角色就是tftp服务器端,而tftp下载功能实际上就是文件传输.tftp服务器可以建立在虚拟机linux下,也可以建立 ...

  5. cURL 是一个功能强大的PHP库。

    使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了.无论是你想从从一个链接上取部分数据,或是取一个XML文件并把 ...

  6. curl smtp libcurl 邮件功能使用

    /* * For an SMTP example using the multi interface please see smtp-multi.c. */ /* The libcurl option ...

  7. CURL 和LIBCURL C++代码 上传本地文件,好不容易碰到了这种折腾我几天的代码

    解决了什么问题:curl在使用各种方式上传文件到服务器.一般的文件上传是通过html表单进行的,通过CURL可以不经过浏览器,直接在服务器端模拟进行表单提交,完成POST数据.文件上传等功能. 服务器 ...

  8. 在linux下实现UBOOT的TFTP下载功能

    一.环境 1.条件 软件:虚拟机下linux(本文涉及到的是Ubuntu12.0.4). linux下的串口助手(例如minicom)或windows下的串口助手(例如超级终端.SecureCRT) ...

  9. 海思平台交叉编译curl支持SSL功能

    1.准备工具 1).交叉编译工具 2).下载libcurl和openssl源代码,我使用的是(openssl-1.0.2o.tar,curl-7.59.0.tar) 3).查看cpu详细 ~ # ca ...

随机推荐

  1. Docker安装并运行mysql5.6数据库

    1.在/home目录下新建mysql目录 mysql目录中新建三个目录:conf目录.logs目录.data目录,建这些目录的目的是用来挂载docker中的mysql下的目录的. 结果如下: 1.1. ...

  2. Saltstack_使用指南11_配置管理-状态之间依赖关系

    1. 说明 下文的案例是根据上一篇文章进行的修改.因此请优先读取上一篇文章内容<Saltstack_10_配置管理-状态模块> 并且目录进行了变化,从 /srv/salt/lamp 变为了 ...

  3. 设备树处理之——device_node转换成platform_device【转】

    转自:https://www.cnblogs.com/downey-blog/p/10486568.html 以下讨论基于linux4.14,arm平台 platform device 设备树的产生就 ...

  4. PyCharm2019.3专业版激活

    1. 首先到官网下载Professional(专业版),链接地址: https://www.jetbrains.com/pycharm/download/ 具体安装方法这里就不赘述 2. 下载补丁je ...

  5. is ==的区别 编码和解码

    1.n=0 n1=0 print(n==n1) ==>true  == 是比较两边的值 2.a="alex " b="alex" print(a==b)= ...

  6. unittest,requests,assertEqual实战演练

    请求方式:POST请求url:https://api.apiopen.top/developerLogin请求参数:名称 类型 必须 描述 示例name string 是 账号 peakchaopas ...

  7. python27期尚哥讲TCP:

    TCP:传输控制协议(使用情况多于udp) 稳定:保证数据一定能收到 相对UDP会慢一点 web服务器一般都使用TCP(银行转账,稳定比快要重要)TCP通信模型: 在通信之前,必须先等待建立链接 TC ...

  8. JavaScript中的数组Array

    抄自:https://www.jianshu.com/p/7e160067a06c js中数组的方法种类众多,有ES5之前版本中存在的,ES5新增,ES6新增等:并且数组的方法还有原型方法和从obje ...

  9. IntelliJ IDEA安装与破解教程(一)

    官网地址:https://www.jetbrains.com/idea/ IntelliJ IDEA分为:旗舰版(Ultimate).社区版(Community) 旗舰版是收费的,社区版则是免费的.旗 ...

  10. 鲜贝7.3--mysql安装

    1.安装包下载 首先是下载 mysql-installer-community-5.6.14.0.msi ,大家可以到 mysql 官方网去下载. win10的安全机制比较严格,安装前最好到<设 ...