cURL / Mailing Lists / curl-library / Single Mail

curl-library

FTP Disconnect by peer problem

From: John Coffey <johnco3_at_gmail.com>
Date: Sun, 27 Apr 2014 01:51:36 -0400

Hello,

this is my first posting to the curl-library mailing list. I believe that
I may have discovered a new bug in libCurl 7.36 and hopefully here is the
place to ask for either a workaround or a solution. I am running on
windows 8.1 and I built libCurl x64 using Visual Studio 2013 and CMake
2.8.12.2 using the following to generate the makefile.

cmake -G "Visual Studio 12 Win64”

I am writing a high level scripting engine that communicates with an
embedded FTP server. The remote FTP server has several modes of operation
(download mode, upload mode kernel mode etc) that are changed through a
special 'site' command sequence sent to the server. I send these using
the curl_easy_setopt(curl, CURLOPT_QUOTE, slist);

The problem is that these servers can do one of 3 things in response to a
QUOTE SITE XXX command

(1) return a 500 error code indicating that the SITE XXX command failed -
libCurl then uncleanly severs the connection - (without sending a QUIT).
 Typically the ftp server (like tnftpd on a mac) will indicated “you might
have said goodbye” in the subsequent packet.

(2) with a successful error code (1XX/2XX) lib curl leaves the connection
open and subsequent ftp operations executed with curl_easy_perform progress
normally.

(3) with an immediate RST packet from the ftp server (effectively resulting
from a connection reset by peer) - this happens because the server reboots
to the requested mode specified in the SITE command without sending a 200
or other type of successful acknowledgement of the request.

Case 3 above is the cause of the creashes in libCurl I am encountering when
I attempt to use the (just closed without notification) connection the for
a subsequent SITE XXX or other command - even listing a directory - (the
idea is that these site commands are run back to back (it is a script
engine)). LibCurl crashes somewhere in ftp.c (I will have access to the
system where I can reproduce the problem on Monday and will add more
details then). If meanwhile there is something obvious wrong or if this is
a known bug - from a search I cannot see it to be so -

The code below shows how I initialize the curl easy options - I have set
the verbose flag on and I can see that curl does its best to always reuse
connections. Is there any way to know when a remote peer sends a RST
packet to sever the connection? My initial thought there may be some
socket callback mechanism to do that, however I am a newbie at libCurl.

Any help would be much appreciated

John

/**
 * Sets the curl options using the current mContextInfo.
 *
 * This never sets the URI curl field as this must be
 * done outside the context object.
 */
void
SLDBContext::setCurlOptions() {
    CURL* pCurl = mCurlHandle.get();
    // reset all curl context info
    curl_easy_reset(pCurl);
    // remoote server does not support EPSV or EPRT
    auto res = curl_easy_setopt(pCurl, CURLOPT_FTP_USE_EPSV, 0L);
    res = curl_easy_setopt(pCurl, CURLOPT_VERBOSE, 1L);
    res = curl_easy_setopt(pCurl, CURLOPT_FTP_USE_EPRT, 0L);
    // do not perform CWD when traversing the pseudo directories
    res = curl_easy_setopt(pCurl, CURLOPT_FTP_FILEMETHOD,
CURLFTPMETHOD_NOCWD);
    res = curl_easy_setopt(pCurl, CURLOPT_CONNECTTIMEOUT,
getConnectTimeoutSecs());
    if (!isPASVMode()) {
        res = curl_easy_setopt(pCurl, CURLOPT_FTPPORT, "-");
    }
    if (mHeaderCallback) {
        res = curl_easy_setopt(pCurl, CURLOPT_WRITEHEADER, &mHeaderStream);
        res = curl_easy_setopt(pCurl, CURLOPT_HEADERFUNCTION,
mHeaderCallback);
    }
    if (mWriteDataCallback) {
        res = curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, mMemBuffer.get());
        res = curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION,
mWriteDataCallback);
    }
}

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-04-27