cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: FTP upload issue

From: Carlos Rimola <crimola_at_gmail.com>
Date: Wed, 2 Nov 2016 11:15:30 -0700

On Wed, Nov 2, 2016 at 9:41 AM, Dan Fandrich <dan_at_coneharvesters.com> wrote:

> On Tue, Nov 01, 2016 at 06:37:36PM -0700, Carlos Rimola wrote:
> > I am a relative newbie to libcurl and I hope someone can help me with an
> issue
> > I am having performing FTP uploads. First, some background:
> >
> > 1) I need to use the multi-interface.
> >
> > 2) I started with the ftpupload.c example. I modified it to add
> mcurl_init, add
> > the easy_handle, etc. That all works fine. I called that ftpuploadm.c.
> It's
> > pretty much ftpupload.c with minor "multi" modifications.
> >
> > 3) The data I need to upload I have no control over and is part of large
> > embedded system. The data comes to me via a "channel" in 256 byte chunks.
> > Therefore the parameter I pass to my read_callback is not a file
> descriptor.
> >
> > 4) I have tried passing the data pointer and length in a data structure
> up to
> > the read_callback. I have also tried reading the "channel" within the
> callback.
> >
> >
> > The problem I see is that data on the channel is always ready
> (available) and
> > the first 10 times I call curl_multi_perform. My read_callback is not
> invoked.
>
> If it's not invoked, then it's not time to send the data to the other side
> yet.
>

Is there a way for me to know when it is time to send the data? That is,
how do I know when libcurl has established the control and data socket
connections, logged in and executed my FTP commands (slist).

As I understand it calling curl_multi-perform, my read_callback copies the
data to the ptr (first) parameter to callback and return the amount of data
copied. This all works fine in my code after the control and data sockets
are setup (as shown by using the option CURLOPT_VERBOSE).

It seems like I am calling curl_multi_perform prematurely but how do I know
when libcurl is ready to send and can call curl_multi_perform knowing that
my read_callback will be invoked?

> > I turned the VERBOSE option on and I can see what is going but have
> tried a
> > number of things and I can't avoid the condition.
>
> I don't who to what "the condition" refers.
>

The "condition" refers to calling curl_multi_perform and my read_callback
not being invoked, therefore - no data sent.

> > What VERBOSE shows is that during those first 10 calls to
> curl_multi_perform,
> > the FTP control socket connection is being established (I assume the data
> > socket as well). It is only when it reaches its end (I see " < 150 Ok to
> send
> > data" that my callback is then called consistently and successfully on
> each
> > call to curl_multi_perform. However, I end up with a transfer that is
> 2560
> > bytes short (256 x 10).
>
> libcurl will send whatever data you pass to it. Have you set the correct
> data
> length with CURLOPT_INFILESIZE_LARGE?

Yes.

> Are you returning the correct value from
> the read data callback?

Yes.

> Are you setting the correct binary vs. ASCII mode for
> the URL?
>

Yes. I am doing binary transfers (the default) and I see libcurl sending
"TYPE I" implicitly.

>
> > Is there any way to establish the control and data connections and know
> they
> > are established so that calling curl_multi_perform will invoke my
> read_callback
> > (when the connection is established, logged in and all is ready)?
>
> libcurl will invoke the read callback function when it's ready to send
> data.
> There is no need for the application to know where libcurl is in its
> transfer
> state machine; just pass data when it's requested and libcurl will handle
> the
> rest.
>

I understand this and I don't need to know when libcurl is in its transfer
state machine. I just need to know when it's safe to call
curl_multi_perform knowing that libcurl is ready and the curl_multi_perform
call will be sure to trigger the invocation to my read_callback so that it
can provide the data and length to transfer.

> >>> Dan
>

Thanks for your reply Dan,

Carlos

> -------------------------------------------------------------------
> List admin: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette: https://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-11-02