cURL / Mailing Lists / curl-users / Single Mail

curl-users

How to enable SCP support in libcurl ..?

From: Yuvi yuvi <testandroidos51_at_gmail.com>
Date: Sat, 25 Feb 2012 14:15:50 +0530

Hi,

I want to enable SCP support in libcurl the steps I followed are :

$sudo apt-get install libssl-dev
$sudo apt-get install libssh2-1-dev

To configure libcurl :

./configure --with-ssl --with-libssh2 --prefix=/home/yuvi/development/curlssh

After configuration I can see that SCP is Enabled.

  curl version: 7.24.0
  Host setup: x86_64-unknown-linux-gnu
  Install prefix: /home/yuvi/development/curlssh
  Compiler: gcc
  SSL support: enabled (OpenSSL)
  SSH support: enabled (libSSH2)
  zlib support: enabled
  krb4 support: no (--with-krb4*)
  GSSAPI support: no (--with-gssapi)
  SPNEGO support: no (--with-spnego)
  TLS-SRP support: no (--enable-tls-srp)
  resolver: default (--enable-ares / --enable-threaded-resolver)
  ipv6 support: enabled
  IDN support: no (--with-libidn)
  Build libcurl: Shared=yes, Static=yes
  Built-in manual: enabled
  Verbose errors: enabled (--disable-verbose)
  SSPI support: no (--enable-sspi)
  ca cert bundle: /etc/ssl/certs/ca-certificates.crt
  ca cert path: no
  LDAP support: no (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS support: no (--enable-ldaps)
  RTSP support: enabled
  RTMP support: no (--with-librtmp)
  Protocols: DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS
POP3 POP3S RTSP SCP SFTP SMTP SMTPS TELNET TFTP

But when I run the sample program I am getting following error :

* Protocol scp not supported or disabled in libcurl
* Unsupported protocol

My url is :

curl_easy_setopt(curl, CURLOPT_URL,"scp://192.168.10.1/mnt/dev.zip");

I am able to retrieve file using command prompt through SCP, it means that
remote server supports SCP. Then where I am doing wrong...?

The complete code snippet is here :

#include <stdio.h>

#include <curl/curl.h>

/*

 * This is an example showing how to get a single file from an FTP server.

 * It delays the actual destination file creation until the first write

 * callback so that it won't create an empty file in case the remote file

 * doesn't exist or something else fails.

 */

struct FtpFile {

  const char *filename;

  FILE *stream;

};

static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void
*stream)

{

  struct FtpFile *out=(struct FtpFile *)stream;

  if(out && !out->stream) {

    /* open file for writing */

    out->stream=fopen(out->filename, "wb");

    if(!out->stream)

      return -1; /* failure, can't open file to write */

  }

  return fwrite(buffer, size, nmemb, out->stream);

}

int main(void)

{

  CURL *curl;

  CURLcode res;

  struct FtpFile ftpfile={

    "curl.tar.gz", /* name to store the file as if succesful */

    NULL

  };

  curl_global_init(CURL_GLOBAL_DEFAULT);

  curl = curl_easy_init();

printf( "%s", curl_version_info(CURLVERSION_NOW)->protocols);

  if(curl) {

    /*

     * You better replace the URL with one that works!

     */

    curl_easy_setopt(curl, CURLOPT_URL,

                     "scp://192.168.10.1/mnt/dev.zip");

    /* Define our callback to get called when there's data to be written */

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);

    /* Set a pointer to our struct to pass to the callback */

    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);

    /* Switch on full protocol/debug output */

    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);

    /* always cleanup */

    curl_easy_cleanup(curl);

    if(CURLE_OK != res) {

      /* we failed */

      fprintf(stderr, "curl told us %d\n", res);

    }

  }

  if(ftpfile.stream)

    fclose(ftpfile.stream); /* close the local file */

  curl_global_cleanup();

  return 0;

}

Thanks,

 Yuvi

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-02-25