- 论坛徽章:
- 0
|
新写的一个程序打算用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;
} |
|