curl-library
Re: FTP of growing files?
Date: Tue, 3 Mar 2015 18:21:42 -0800
It looks like I can use the CURLOPT_IGNORE_CONTENT_LENGTH to control this
behavior with a small change to ftp_state_quote():
static CURLcode ftp_state_quote(struct connectdata *conn,
bool init,
ftpstate instate)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
bool quote=FALSE;
struct curl_slist *item;
switch(instate) {
case FTP_QUOTE:
default:
item = data->set.quote;
break;
case FTP_RETR_PREQUOTE:
case FTP_STOR_PREQUOTE:
item = data->set.prequote;
break;
case FTP_POSTQUOTE:
item = data->set.postquote;
break;
}
/*
* This state uses:
* 'count1' to iterate over the commands to send
* 'count2' to store wether to allow commands to fail
*/
if(init)
ftpc->count1 = 0;
else
ftpc->count1++;
if(item) {
int i = 0;
/* Skip count1 items in the linked list */
while((i< ftpc->count1) && item) {
item = item->next;
i++;
}
if(item) {
char *cmd = item->data;
if(cmd[0] == '*') {
cmd++;
ftpc->count2 = 1; /* the sent command is allowed to fail */
}
else
ftpc->count2 = 0; /* failure means cancel operation */
PPSENDF(&ftpc->pp, "%s", cmd);
state(conn, instate);
quote = TRUE;
}
}
if(!quote) {
/* No more quote to send, continue to ... */
switch(instate) {
case FTP_QUOTE:
default:
result = ftp_state_cwd(conn);
break;
case FTP_RETR_PREQUOTE:
if(ftp->transfer != FTPTRANSFER_BODY)
state(conn, FTP_STOP);
else {
if(ftpc->known_filesize != -1) {
Curl_pgrsSetDownloadSize(data, ftpc->known_filesize);
result = ftp_state_retr(conn, ftpc->known_filesize);
}
else {
// New code highlighted
if (data->set.ignorecl) {
PPSENDF(&ftpc->pp, "RETR %s", ftpc->file);
state(conn, FTP_RETR);
}
else {
PPSENDF(&ftpc->pp, "SIZE %s", ftpc->file);
state(conn, FTP_RETR_SIZE);
}
}
}
break;
case FTP_STOR_PREQUOTE:
result = ftp_state_ul_setup(conn, FALSE);
break;
case FTP_POSTQUOTE:
break;
}
}
return result;
}
This prevents the file size from being queried within the context of the
transfer request (data->set.ignorecl is set to the value of
CURLOPT_IGNORE_CONTENT_LENGTH).
On Tue, Mar 3, 2015 at 9:51 AM, Kurt Fankhauser <kurtbutfrank_at_gmail.com>
wrote:
>
>
> On Mon, Mar 2, 2015 at 12:29 AM, Tor Arntsen <kspt.tor_at_gmail.com> wrote:
>
>> But FTP is not optimal for this, are
>> you lmiited to FTP only? Because with HTTP, for example, it's pretty
>> easy to handle.
>>
>> Perhaps FTP was not the best choice for this, but alas, that choice was
> made a long time ago by others and now I must connect to the existing
> equipment that contains the FTP server which supports growing files.
>
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-03-04