cURL / Mailing Lists / curl-library / Single Mail

curl-library

SCP using libcurl ...

From: Sandro Andrade <sandro.andrade_at_gmail.com>
Date: Wed, 24 Oct 2007 09:53:23 -0300

Hi all,

I'm trying to use libcurl for upload and download files to/from a ssh server
by using the scp protocol.
I suppose that two methods are available to do this:

1) Inform the user and password when connecting to the server
2) Use certificates for authentication

Is this correct ?

I've developed this code (using the method 1) and it's working for uploading
files to the ssh server:

  fd = fopen("debugit", "rb"); /* open file to upload */
  ...
  curl = curl_easy_init();
  if(curl) {
    /* upload to this place */
    curl_easy_setopt(curl, CURLOPT_URL,
                     "scp://<my_host>:<my_port>/home/sandros/debugit");

    /* adjust user and password */
    curl_easy_setopt(curl, CURLOPT_USERPWD,
                     "<username>:<password>");

    /* tell it to "upload" to the URL */
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);

    /* set where to read from (on Windows you need to use READFUNCTION too)
*/
    curl_easy_setopt(curl, CURLOPT_READDATA, fd);

    /* and give the size of the upload (optional) */
    //curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
    // (curl_off_t)file_info.st_size);

    /* and give the size of the upload (optional) */
    curl_easy_setopt(curl, CURLOPT_INFILESIZE,
                     (long)file_info.st_size);

    /* enable verbose for easier tracing */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

    res = curl_easy_perform(curl);

    /* now extract transfer info */
    curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
    curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);

    fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n",
            speed_upload, total_time);

    /* always cleanup */
    curl_easy_cleanup(curl);

   ...

My questions are:

1) Is this approach correct ? I mean, am I using a really secure connection
without inform the certificates ? Are there any other benefits for use of
certificates besides the no need of username and password ?

2) If I use curl_easy_setopt with the CURLOPT_INFILESIZE_LARGE parameter I
get the error "SCP requires a known file size for upload". Why ? debugit is
a very simple and short text file.

Thanks in advance,

-- 
Sandro Santos Andrade
--------------------------------------------------------
Distributed Systems Laboratory (LaSiD)
Computer Science Department (DCC)
Federal University of Bahia
Brazil
Received on 2007-10-24