cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: retreive messages [with PATCH]

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 4 Jan 2002 15:55:36 +0100 (MET)

On Fri, 4 Jan 2002, raoul cridlig wrote:

> Is that the way to get ftp lines ? :
>
> curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION,
> WriteMemoryCallback);
> curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);

If you want to pass a "custom pointer" to the CURLOPT_HEADERFUNCTION,
callback, use CURLOPT_WRITEHEADER.

I just wrote a little program that does this, and this works for me...

size_t write_response(void *ptr, size_t size, size_t nmemb, void *data)
{
  FILE *writehere = (FILE *)data;
  return fwrite(ptr, size, nmemb, writehere);
}

int main(int argc, char **argv)
{
  CURL *curl;
  CURLcode res;
  FILE *ftpfile;
  FILE *respfile;

  /* local file name to store the file as */
  ftpfile = fopen("ftp-list", "wb"); /* b is binary, needed on win32 */

  /* local file name to store the response lines in */
  respfile = fopen("ftp-responses", "wb"); /* b is binary, needed on win32 */

  curl = curl_easy_init();
  if(curl) {
    /* Get curl 7.7 from sunet.se's FTP site: */
    curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/");
    curl_easy_setopt(curl, CURLOPT_FILE, ftpfile);
    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response);
    curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile);
    res = curl_easy_perform(curl);

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

  fclose(ftpfile); /* close the local file */
  fclose(respfile); /* close the local file */

  return 0;
}

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2002-01-04