cURL / Mailing Lists / curl-library / Single Mail

curl-library

FTP get file in binary mode

From: Ashish Nigam <anigam_at_inmage.net>
Date: Mon, 20 Dec 2004 21:02:35 -0800

Hi,
I have to download a file from FTP server machine in binary mode. Simple isn't it. But I am not able to figure out the right way till now.
As far as I know, there can be three options -

1) Set CURLOPT_URL to complete path of the file like ftp://<server_name>/path_to_file
    The problem with this option is that it logs to home directory of the user rather than root or / .
    And in this case, absolute path will fail because curl will try to CWD path_to_file which is true with respect to root rather than user home directory.

2) Use CURLOPT_QUOTE option with RETR command - I have tried many combinations, but it seems to hang in RETR.
    Here's one code snippet
headerlist = curl_slist_append(headerlist, "CWD /");
headerlist = curl_slist_append(headerlist, "CWD /tmp");
headerlist = curl_slist_append(headerlist, "TYPE I");
headerlist = curl_slist_append(headerlist, "PASV");
headerlist = curl_slist_append(headerlist, "RETR test.zip");

As it hangs in RETR, I am sure I am doing something wrong in this approach, or I am totally out of my mind :-)

3) Use CURLOPT_CUSTOMREQUEST option with RETR - This works but file download is done in ASCII mode and I am not able to get it transfer in binary mode.

So please help me out.
Any suggestions will be appreciated.

Thanks
Received on 2004-12-21