curl-library
Re: Pb with FTP transfert
Date: Fri, 29 Aug 2014 11:48:41 +0000
Le jeudi 28 août 2014 à 19:09 +0200, Daniel Stenberg a écrit :
On Thu, 28 Aug 2014, Eric Bouxirot wrote:
> i make some FTP transferts with libcurl. but i have big trouble using
> progress bar.. the progress bar show up but nothing change .. i always get 0
> bytes and no speed. i have test to add custom progress bar but bytes counter
> stay to 0. this for upload or download...
> what i'm doing wrong ?
So show us your code and we might have an idea!
hi,
here my libCURL versoin:
#define LIBCURL_VERSION_NUM 0x071d00
here my code:
**early in my startup code:
curl_global_init(CURL_GLOBAL_ALL);
**now, in my FTP worker:
static int _CUrlXferInfo_cb(void* pv_InPrivate, curl_off_t t_InDlTotal, curl_off_t t_InDlCurrent, curl_off_t t_InUlTotal, curl_off_t t_InUlCurrent)
{
s_CUrlProgress* ps_LocProgress;
double d_LocCurrentTime;
ps_LocProgress=pv_InPrivate;
d_LocCurrentTime=0;
curl_easy_getinfo(ps_LocProgress->pt_CUrl, CURLINFO_TOTAL_TIME, &d_LocCurrentTime);
if((d_LocCurrentTime-ps_LocProgress->d_LastTime)>=CURLPROGRESS_DELAY || (ps_LocProgress->b_Upload && t_InUlCurrent==t_InUlTotal && t_InUlTotal) || (!ps_LocProgress->b_Upload && t_InDlCurrent==t_InDlTotal && t_InDlTotal))
{
ps_LocProgress->d_LastTime=d_LocCurrentTime;
if (ps_LocProgress->b_Upload)
{
printf(KCYN"FTP: Upload %02d.%02d - %0.3fkB / %0.3fkB (~%0.3fkB/s)\n"KNRM, (int)d_LocCurrentTime/60, (int)d_LocCurrentTime%60, (double)t_InUlCurrent/1024, (double)t_InUlTotal/1024, ((double)t_InUlCurrent/d_LocCurrentTime)/1024);
if (((int)t_InUlCurrent-ps_LocProgress->pt_LastCount)>100)
{
ps_LocProgress->pt_LastCount=t_InUlCurrent;
MODEM_HoldOn(0);
}
}
else
{
printf(KBLU"FTP: Download %02d.%02d - %0.3fb / %0.3fb (~%0.3fkB/s)\n"KNRM, (int)d_LocCurrentTime/60, (int)d_LocCurrentTime%60, (double)t_InDlCurrent/1024, (double)t_InDlTotal/1024, ((double)t_InDlCurrent/d_LocCurrentTime)/1024);
if (((int)t_InDlCurrent-ps_LocProgress->pt_LastCount)>100)
{
ps_LocProgress->pt_LastCount=t_InDlCurrent;
MODEM_HoldOn(0);
}
}
if(MODEM_isConnected()==FALSE)
{
printf(KRED"FTP: Modem is no more connected. Aborting current transfert\n"KNRM);
return 1;
}
}
return 0;
}
static int _CUrlProgress_cb(void* pv_InPrivate, double d_InDlTotal, double d_InDlCurrent, double d_InUlTotal, double d_InUlCurrent)
{
return _CUrlXferInfo_cb(pv_InPrivate, (curl_off_t)d_InDlTotal, (curl_off_t)d_InDlCurrent, (curl_off_t)d_InUlTotal, (curl_off_t)d_InUlCurrent);
}
static void _InitCUrlProgress(s_CUrlProgress* ps_InProgressData, CURL* pt_InCUrl, BOOL b_InUpload)
{
ps_InProgressData->d_LastTime=0-CURLPROGRESS_DELAY; // This is for a first immediate display
ps_InProgressData->pt_CUrl=pt_InCUrl;
ps_InProgressData->pt_LastCount=0;
ps_InProgressData->b_Upload=b_InUpload;
curl_easy_setopt(pt_InCUrl, CURLOPT_PROGRESSFUNCTION, _CUrlProgress_cb);
curl_easy_setopt(pt_InCUrl, CURLOPT_PROGRESSDATA, ps_InProgressData);
#if LIBCURL_VERSION_NUM >= 0x072000
curl_easy_setopt(pt_InCUrl, CURLOPT_XFERINFOFUNCTION, _CUrlXferInfo_cb);
curl_easy_setopt(pt_InCUrl, CURLOPT_XFERINFODATA, ps_InProgressData);
#endif
}
static long _UploadFile(CURL* pt_InCURLCtx, u8* pu8_InRemoteFile, FILE* pt_InFile)
{
long l_LocStatLong;
u8 pu8_LocFTPUrl[200];
CURLcode t_LocCURLResult;
struct curl_slist *pt_Locheaderlist;
u8 pu8_LocCmd1[256];
u8 pu8_LocCmd2[256];
u8* pu8_LocFN;
s_CUrlProgress ps_LocCUrlProgress;
l_LocStatLong=0;
pu8_LocFN=(u8*)strrchr((char*)pu8_InRemoteFile,'/');
if (pu8_LocFN!=NULL)
{
pu8_LocFN++;
sprintf((char*)pu8_LocFTPUrl,"ftp://%s:%d/%s.tmp",_pu8_FTPAddress,_u16_FTPPort,pu8_InRemoteFile);
curl_easy_setopt(pt_InCURLCtx, CURLOPT_URL, pu8_LocFTPUrl);
curl_easy_setopt(pt_InCURLCtx, CURLOPT_NOBODY, 0);
curl_easy_setopt(pt_InCURLCtx, CURLOPT_UPLOAD, 1);
curl_easy_setopt(pt_InCURLCtx, CURLOPT_NOPROGRESS, 0);
_InitCUrlProgress(&ps_LocCUrlProgress,pt_InCURLCtx,TRUE);
pt_Locheaderlist=NULL;
sprintf((char*)pu8_LocCmd1, "RNFR %s.tmp", pu8_LocFN);
pt_Locheaderlist=curl_slist_append(pt_Locheaderlist,(char*)pu8_LocCmd1);
sprintf((char*)pu8_LocCmd2, "RNTO %s", pu8_LocFN);
pt_Locheaderlist=curl_slist_append(pt_Locheaderlist,(char*)pu8_LocCmd2);
curl_easy_setopt(pt_InCURLCtx, CURLOPT_POSTQUOTE, pt_Locheaderlist);
curl_easy_setopt(pt_InCURLCtx, CURLOPT_READDATA, pt_InFile);
t_LocCURLResult=curl_easy_perform(pt_InCURLCtx);
if (t_LocCURLResult==CURLE_OK)
{
curl_easy_getinfo(pt_InCURLCtx, CURLINFO_RESPONSE_CODE, &l_LocStatLong);
}
else
{
l_LocStatLong=-t_LocCURLResult;
}
}
return l_LocStatLong;
}
** CUrl handler issued by this function before calling _UploadFile()
static CURL* _InitCURL(void)
{
CURL *pt_LocCURL;
pt_LocCURL=curl_easy_init();
if(pt_LocCURL!=NULL)
{
curl_easy_setopt(pt_LocCURL, CURLOPT_FTP_USE_EPSV, 1);
curl_easy_setopt(pt_LocCURL, CURLOPT_USERPWD, _pu8_UsrPass);
}
return pt_LocCURL;
}
thank for your help !
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-08-29