cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl and FTP through proxy in Windows

From: Peter Davis <peter78_at_tut.by>
Date: Tue, 28 Jun 2005 17:00:05 +0400

Hello,

I have used this code to receive the list of files from FTP server through
proxy in Windows.
But it stops responding on setting up a transfer connection for recieive the
list of files.
Different proxies and FTP servers I have already tried.
Could you please help me with this?
May be I'm using wrong code? Here is it:

============================================================================
===============
int main(int argc, char **argv)
{
    CURL *curl;
    CURLcode res;

    struct MemoryStruct chunk;
    chunk.memory=NULL; // we expect realloc(NULL, size) to work
    chunk.size = 0; // no data at this point

    curl = curl_easy_init();
    if (curl)
    {
        // Get a file listing from FTP
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

        // specify file directory to LIST
        curl_easy_setopt(curl, CURLOPT_URL, "ftp://localhost");

        curl_easy_setopt(curl, CURLOPT_PORT, 21);

        // send all data to this function
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);

        // proxy server
        curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1);
        curl_easy_setopt(curl, CURLOPT_PROXY, "192.168.15.1:808");
        curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);

        // set timeout
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);

        res = curl_easy_perform(curl);

        if (chunk.memory)
        {
            fwrite(chunk.memory, chunk.size, 1, stderr);
            free(chunk.memory);
        }

        /* always cleanup */
        curl_easy_cleanup(curl);
    }

    return 0;
}
============================================================================
===============

Here is what I get:
============================================================================
===============
* About to connect() to 192.168.15.1 port 808
* Trying 192.168.15.1... * connected
* Connected to 192.168.15.1 (192.168.15.1) port 808
* Establish HTTP proxy tunnel to localhost:21
> CONNECT localhost:21 HTTP/1.0
Host: localhost:21
Proxy-Connection: Keep-Alive

< HTTP/1.0 200 Connection established
< Proxy-agent: CCProxy 6.2
<
* Proxy replied OK to CONNECT request
< 220 Welcome to Pablo's FTP Server
> USER anonymous
< 331 Password required for anonymous
> PASS curl_by_daniel_at_haxx.se
< 230 User successfully logged in.
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> EPSV
* Connect data stream passively
< 502 Command not implemented - Try HELP.
* disabling EPSV usage
> PASV
< 227 Entering Passive Mode (127,0,0,1,16,53).
* Trying 192.168.15.1... * connected
* Connecting to 127.0.0.1 (192.168.15.1) port 808
* Establish HTTP proxy tunnel to 127.0.0.1:4149
> CONNECT 127.0.0.1:4149 HTTP/1.0
Host: 127.0.0.1:4149
Proxy-Connection: Keep-Alive
============================================================================
===============

The same code but without proxy returns:
============================================================================
===============
* About to connect() to localhost port 21
* Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 21
< 220 Welcome to Pablo's FTP Server
> USER anonymous
< 331 Password required for anonymous
> PASS curl_by_daniel_at_haxx.se
< 230 User successfully logged in.
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> EPSV
* Connect data stream passively
< 502 Command not implemented - Try HELP.
* disabling EPSV usage
> PASV
< 227 Entering Passive Mode (127,0,0,1,16,77).
* Trying 127.0.0.1... * connected
* Connecting to 127.0.0.1 (127.0.0.1) port 4173
> TYPE A
< 200 Type set to A
> LIST
< 150 Opening ASCII mode data connection for directory list.
< 226 Transfer complete
* Connection #0 to host localhost left intact
drwx------ 1 user group 0 Jun 26 10:09 max
-rwx------ 1 user group 0 Jun 26 10:09 robot.me
> QUIT
< 220 Bye
* Closing connection #0
============================================================================
===============

Thanks
Peter
Received on 2005-06-28