免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1861 | 回复: 0
打印 上一主题 下一主题

libcurl使用问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-28 11:33 |只看该作者 |倒序浏览
新写的一个程序打算用libcurl库实现上传文件功能。下面是实现ftp功能的函数。主函数中不调用该函数执行后用top查看(VIRT  RES).基本能保持在一个固定值。调用该函数后(VIRT  RES).都会逐渐增大。这是啥原因?是函数哪里有问题?需要怎么修正?

int ftpupload(char *ip,char *account,char *logfile)
{
        char full_path[PATH_MAX],*logbasename,remote_url[PATH_MAX];
        CURL *curl;
        CURLcode res;
        FILE *hd_src;
        //计算日志全完整路径
        strcpy(full_path,TRANSLOG_ROOT);
        strcat(full_path,logfile);
        logbasename = basename(full_path);
       
        //计算上传地址
        sprintf(remote_url,"ftp://%s/%s",ip,logbasename);

        if (access(full_path,F_OK)==0)
        {
                hd_src = fopen(full_path,"rb");
                curl = curl_easy_init();
                if (curl)
                {
                        curl_easy_setopt(curl,CURLOPT_UPLOAD,1L);
                        //curl_easy_setopt(curl,CURLOPT_VERBOSE,1L);
                        curl_easy_setopt(curl,CURLOPT_USERPWD,account);
                        curl_easy_setopt(curl,CURLOPT_FTP_CREATE_MISSING_DIRS,1L);
                        curl_easy_setopt(curl,CURLOPT_URL,remote_url);
                        curl_easy_setopt(curl,CURLOPT_READDATA,hd_src);
                        res = curl_easy_perform(curl);
                        if (res != 0)
                        {
                                //清理工作
                                syslog(LOG_LOCAL0|LOG_ERR,"perform upload error: %s\n",curl_easy_strerror(res));
                                curl_easy_cleanup(curl);
                                fclose(hd_src);
                                return res;
                        }
                        curl_easy_cleanup(curl);
                }
                fclose(hd_src);
        }else{
                //清理工作
                syslog(LOG_LOCAL0|LOG_ERR,"upload file %s not access\n",full_path);
                return -1;
        }
        return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP