cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker mailing list Archives

[ curl-Bugs-1600447 ] Active FTP upload/download with multi interface.

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Tue, 21 Nov 2006 06:25:40 -0800

Bugs item #1600447, was opened at 2006-11-21 06:25
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=1600447&group_id=976

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: ftp
Group: hang
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Daniel Stenberg (bagder)
Summary: Active FTP upload/download with multi interface.

Initial Comment:
Hi,

I'm trying to use multi interface for active FTP upload/download and have some problem similar to described here: http://curl.haxx.se/mail/lib-2006-06/0023.html.

The process hangs up after a reply on PORT command is receved. Here is the verbose output:

* About to connect() to ftp.sunet.se port 21 (#0)
* Trying 194.71.11.70... * Connected to ftp.sunet.se (194.71.11.70) port 21 (#
0)
< 220 Welcome to ftp.sunet.se
> USER anonymous
< 331 Any password will work
> PASS curl_by_daniel_at_haxx.se
< 230 Any password will work
> PWD
< 257 "/" is your current location
* Entry path is '/'
> CWD pub
< 250 OK. Current directory is /pub
> CWD www
< 250 OK. Current directory is /pub/www
> CWD utilities
< 250 OK. Current directory is /pub/www/utilities
> CWD curl
< 250 OK. Current directory is /pub/www/utilities/curl
* Telling server to connect to 85.202.18.127:3969
> PORT 85,202,18,127,15,129
< 200 PORT command successful
* Connect data stream actively

Need to note that sometimes the program runs as expected without hanging,
but this happens very rarely.

libcurl version(from RELEASE-NOTES):
        Curl and libcurl 7.16.0

                 Public curl release number: 96
                 Releases counted from the very beginning: 123
                 Available command line options: 112
                 Available curl_easy_setopt() options: 133
                 Number of public functions in libcurl: 54
                 Amount of public web site mirrors: 37
                 Number of known libcurl bindings: 35
                 Number of contributors: 515

OS: Microsoft Windows Server 2003, Enterprise Edition, SP1, v1039.
Compiler: MS Visual C++ 6.0
FTP server: I've tried with several FTP servers: IIS 6.0,
            FileZilla Server v0.9.20 beta and some other.
            It hangs with all of them.
            
There was no firewall between ftp client and server.

I've attached a simple test project to reproduce the problem (CURLFailure.zip).

After investigating libcurl sources and some debugging it seems to me
that problem is in function
static CURLMcode multi_runsingle(struct Curl_multi *multi,
                                 struct Curl_one_easy *easy)
from multi.c file.

More precisely in the piece of code below:

    case CURLM_STATE_DO_MORE:
      /* Ready to do more? */
      easy->result = Curl_is_connected(easy->easy_conn,
                                       SECONDARYSOCKET,
                                       &connected);
      if(connected) {
        /*
         * When we are connected, DO MORE and then go DO_DONE
         */
        easy->result = Curl_do_more(easy->easy_conn);

        if(CURLE_OK == easy->result)
          easy->result = Curl_readwrite_init(easy->easy_conn);
        else
          /* Remove ourselves from the send pipeline */
          Curl_removeHandleFromPipeline(easy->easy_handle,
                                        easy->easy_conn->send_pipe);

        if(CURLE_OK == easy->result) {
          multistate(easy, CURLM_STATE_DO_DONE);
          result = CURLM_CALL_MULTI_PERFORM;
        }
      }
      break;
      
There are two issues from my point of view:

1) In active mode SECONDARYSOCKET is listening, but function Curl_is_connected(...)
   checks if socket is connected. I mean that it puts SECONDARYSOCKET to fds_write
   and call select(), which always returns 0 since SECONDARYSOCKET is listening.
   That is why even if FTP server tries to connect on specified port immediatelly
   after PORT command, the flag connected is always false. This leads to hanging up.

2) All FTP servers I've tried do not connect immediatelly after PORT command. They
   do this after RETR or STOR command. That means that we have to wait for new
   connection from FTP server after RETR command is sent.

So quick fix I've maid is the next:

    case CURLM_STATE_DO_MORE:
      if(!easy->easy_conn->data->set.ftp_use_port) {
          /* Ready to do more? */
        easy->result = Curl_is_connected(easy->easy_conn,
                                         SECONDARYSOCKET,
                                         &connected);
      }
      
      if(connected || easy->easy_conn->data->set.ftp_use_port ) {
        /*
         * When we are connected, DO MORE and then go DO_DONE
         */
        easy->result = Curl_do_more(easy->easy_conn);

        if(CURLE_OK == easy->result)
          easy->result = Curl_readwrite_init(easy->easy_conn);
        else
          /* Remove ourselves from the send pipeline */
          Curl_removeHandleFromPipeline(easy->easy_handle,
                                        easy->easy_conn->send_pipe);

        if(CURLE_OK == easy->result) {
          multistate(easy, CURLM_STATE_DO_DONE);
          result = CURLM_CALL_MULTI_PERFORM;
        }
      }
      break;

Now it works good with all FTP servers.
But the only thing I'm worried about that with such fix the next call is blocking:
        easy->result = Curl_do_more(easy->easy_conn)
because there is a select() with 60 seconds timeout in it. Obviously that is not good if
we use multi interface.

Could you please suggest another way to fix the problem?

Thanks,
Alexey Simak

E-mail: alexeysimak_at_gmail.com

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=1600447&group_id=976
Received on 2006-11-21

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET