? .gdb_history
? cURL
? compile
? libssh2_patch.txt
? libssh2_patch.zip
? makePatch.sh
? nonexistant.txt
? rc.conf
? tmp
? lib/sftp.c
? lib/sftp.h
? src/.gdb_history
Index: configure.ac
===================================================================
RCS file: /cvsroot/curl/curl/configure.ac,v
retrieving revision 1.207
diff -u -r1.207 configure.ac
--- configure.ac	16 Oct 2006 08:30:56 -0000	1.207
+++ configure.ac	27 Oct 2006 00:58:40 -0000
@@ -78,6 +78,7 @@
 dnl
 dnl initialize all the info variables
     curl_ssl_msg="no      (--with-ssl / --with-gnutls)"
+ url_libssh2_msg="no      (--with-libssh2)"
    curl_zlib_msg="no      (--with-zlib)"
    curl_krb4_msg="no      (--with-krb4*)"
     curl_gss_msg="no      (--with-gssapi)"
@@ -1044,6 +1045,72 @@
 fi
 
 dnl **********************************************************************
+dnl Check for the presence of LIBSSH2 libraries and headers
+dnl **********************************************************************
+
+dnl Default to compiler & linker defaults for LIBSSH2 files & libraries.
+OPT_LIBSSH2=off
+AC_ARG_WITH(libssh2,dnl
+AC_HELP_STRING([--with-libssh2=PATH],[Where to look for libssh2, PATH points to the LIBSSH2 installation (default: /usr/local/lib); when possible, set the PKG_CONFIG_PATH environment variable instead of using this option])
+AC_HELP_STRING([--without-libssh2], [disable LIBSSH2]),
+  OPT_LIBSSH2=$withval)
+
+if test X"$OPT_LIBSSH2" != Xno; then
+  dnl backup the pre-libssh2 variables
+  CLEANLDFLAGS="$LDFLAGS"
+  CLEANCPPFLAGS="$CPPFLAGS"
+  CLEANLIBS="$LIBS"
+
+  case "$OPT_LIBSSH2" in
+  yes)
+    dnl --with-libssh2 (without path) used
+    PREFIX_LIBSSH2=/usr/local/lib
+    LIB_LIBSSH2="$PREFIX_LIBSSH2/lib$libsuff"
+    ;;
+  off)
+    dnl no --with-libssh2 option given, just check default places
+    PREFIX_LIBSSH2=
+    ;;
+  *)
+    dnl check the given --with-libssh2 spot
+    PREFIX_LIBSSH2=$OPT_LIBSSH2
+    LIB_LIBSSH2="$PREFIX_LIBSSH2/lib$libsuff"
+    LDFLAGS="$LDFLAGS -L$LIB_LIBSSH2"
+    CPPFLAGS="$CPPFLAGS -I$PREFIX_LIBSSH2/include/libssh2 -I$PREFIX_LIBSSH2/include"
+    ;;
+  esac
+
+  if test X"$HAVECRYPTO" = X"yes"; then
+    dnl This is only reasonable to do if crypto actually is there: check for
+    dnl LIBSSH2 libs NOTE: it is important to do this AFTER the crypto lib
+
+    AC_CHECK_LIB(ssh2, libssh2_channel_open_ex)
+    
+    AC_CHECK_HEADERS(libssh2.h,
+      curl_libssh2_msg="enabled (libSSH2)"
+      LIBSSH2_ENABLED=1
+      AC_DEFINE(USE_LIBSSH2, 1, [if libSSH2 is in use]))
+
+    if test X"OPT_LIBSSH2" != Xoff &&
+       test "$LIBSSH2_ENABLED" != "1"; then
+      AC_MSG_ERROR([libSSH2 libs and/or directories were not found where specified!])
+    fi
+  fi
+
+  if test "$LIBSSH2_ENABLED" = "1"; then
+    if test -n "$LIB_LIBSSH2"; then
+       dnl when the libssh2 shared libs were found in a path that the run-time
+       dnl linker doesn't search through, we need to add it to LD_LIBRARY_PATH
+       dnl to prevent further configure tests to fail due to this
+
+       LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$LIB_LIBSSH2"
+       export LD_LIBRARY_PATH
+       AC_MSG_NOTICE([Added $LIB_LIBSSH2 to LD_LIBRARY_PATH])
+    fi
+  fi
+fi
+
+dnl **********************************************************************
 dnl Check for the random seed preferences 
 dnl **********************************************************************
 
@@ -2076,6 +2143,7 @@
   Install prefix:  ${prefix}
   Compiler:        ${CC}
   SSL support:     ${curl_ssl_msg}
+  LIBSSH2 support: ${curl_libssh2_msg}
   zlib support:    ${curl_zlib_msg}
   krb4 support:    ${curl_krb4_msg}
   GSSAPI support:  ${curl_gss_msg}
Index: include/curl/curl.h
===================================================================
RCS file: /cvsroot/curl/curl/include/curl/curl.h,v
retrieving revision 1.310
diff -u -r1.310 curl.h
--- include/curl/curl.h	21 Oct 2006 11:32:07 -0000	1.310
+++ include/curl/curl.h	27 Oct 2006 00:58:48 -0000
@@ -392,6 +392,46 @@
                                     CURLOPT_CONV_FROM_UTF8_FUNCTION */
   CURLE_SSL_CACERT_BADFILE,      /* 77 - could not load CACERT file, missing
                                     or wrong format */
+  /* Error Codes (defined by libssh2) */
+  CURLE_LIBSSH2_ERROR_SOCKET_NONE,                /* 78 - */
+  CURLE_LIBSSH2_ERROR_BANNER_NONE,                /* 79 - */
+  CURLE_LIBSSH2_ERROR_BANNER_SEND,                /* 80 - */
+  CURLE_LIBSSH2_ERROR_INVALID_MAC,                /* 81 - */
+  CURLE_LIBSSH2_ERROR_KEX_FAILURE,                /* 82 - */
+  CURLE_LIBSSH2_ERROR_ALLOC,                      /* 83 - */
+  CURLE_LIBSSH2_ERROR_SOCKET_SEND,                /* 84 - */
+  CURLE_LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE,       /* 85 - */
+  CURLE_LIBSSH2_ERROR_TIMEOUT,                    /* 86 - */
+  CURLE_LIBSSH2_ERROR_HOSTKEY_INIT,               /* 87 - */
+  CURLE_LIBSSH2_ERROR_HOSTKEY_SIGN,               /* 88 - */
+  CURLE_LIBSSH2_ERROR_DECRYPT,                    /* 89 - */
+  CURLE_LIBSSH2_ERROR_SOCKET_DISCONNECT,          /* 90 - */
+  CURLE_LIBSSH2_ERROR_PROTO,                      /* 91 - */
+  CURLE_LIBSSH2_ERROR_PASSWORD_EXPIRED,           /* 92 - */
+  CURLE_LIBSSH2_ERROR_FILE,                       /* 93 - */
+  CURLE_LIBSSH2_ERROR_METHOD_NONE,                /* 94 - */
+  CURLE_LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED,     /* 95 - */
+  CURLE_LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,       /* 96 - */
+  CURLE_LIBSSH2_ERROR_CHANNEL_OUTOFORDER,         /* 97 - */
+  CURLE_LIBSSH2_ERROR_CHANNEL_FAILURE,            /* 98 - */
+  CURLE_LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,     /* 99 - */
+  CURLE_LIBSSH2_ERROR_CHANNEL_UNKNOWN,            /* 100 - */
+  CURLE_LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,    /* 101 - */
+  CURLE_LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,    /* 102 - */
+  CURLE_LIBSSH2_ERROR_CHANNEL_CLOSED,             /* 103 - */
+  CURLE_LIBSSH2_ERROR_CHANNEL_EOF_SENT,           /* 104 - */
+  CURLE_LIBSSH2_ERROR_SCP_PROTOCOL,               /* 105 - */
+  CURLE_LIBSSH2_ERROR_ZLIB,                       /* 106 - */
+  CURLE_LIBSSH2_ERROR_SOCKET_TIMEOUT,             /* 107 - */
+  CURLE_LIBSSH2_ERROR_SFTP_PROTOCOL,              /* 108 - */
+  CURLE_LIBSSH2_ERROR_REQUEST_DENIED,             /* 109 - */
+  CURLE_LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,       /* 110 - */
+  CURLE_LIBSSH2_ERROR_INVAL,                      /* 111 - */
+  CURLE_LIBSSH2_ERROR_INVALID_POLL_TYPE,          /* 112 - */
+  CURLE_LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,         /* 113 - */
+  CURLE_REMOTE_FILE_NOT_FOUND,                    /* 114 - remote file not
+                                                           found */
+  
   CURL_LAST /* never use! */
 } CURLcode;
 
@@ -427,6 +467,14 @@
 #define CURLAUTH_ANY ~0               /* all types set */
 #define CURLAUTH_ANYSAFE (~CURLAUTH_BASIC)
 
+#define CURLSSH2_AUTH_ANY       ~0     /* all types supported by the server */
+#define CURLSSH2_AUTH_NONE      0      /* none allowed, silly but complete */
+#define CURLSSH2_AUTH_PUBLICKEY (1<<0) /* public/private key files */
+#define CURLSSH2_AUTH_PASSWORD  (1<<1) /* password */
+#define CURLSSH2_AUTH_HOST      (1<<2) /* host key files */
+#define CURLSSH2_AUTH_KEYBOARD  (1<<3) /* keyboard interactive */
+#define CURLSSH2_AUTH_DEFAULT CURLSSH2_AUTH_ANY
+
 #ifndef CURL_NO_OLDIES /* define this to test if your app builds with all
                           the obsolete stuff removed! */
 /* this was the error code 50 in 7.7.3 and a few earlier versions, this
@@ -1029,6 +1077,13 @@
      enabled (== 1) */
   CINIT(SSL_SESSIONID_CACHE, LONG, 150),
 
+  /* libssh2 allowed authentication methods */
+  CINIT(SSH_AUTH_TYPES, LONG, 151),
+  
+  /* Used by libssh2 scp/sftp to do public/private key authentication */
+  CINIT(LIBSSH2_PUBLIC_KEYFILE, OBJECTPOINT, 152),
+  CINIT(LIBSSH2_PRIVATE_KEYFILE, OBJECTPOINT, 153),
+  
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
@@ -1506,6 +1561,7 @@
   CURLVERSION_FIRST,
   CURLVERSION_SECOND,
   CURLVERSION_THIRD,
+  CURLVERSION_FOURTH,
   CURLVERSION_LAST /* never actually use this */
 } CURLversion;
 
@@ -1514,7 +1570,7 @@
    meant to be a built-in version number for what kind of struct the caller
    expects. If the struct ever changes, we redefine the NOW to another enum
    from above. */
-#define CURLVERSION_NOW CURLVERSION_THIRD
+#define CURLVERSION_NOW CURLVERSION_FOURTH
 
 typedef struct {
   CURLversion age;          /* age of the returned struct */
@@ -1537,6 +1593,10 @@
 
   /* Same as '_libiconv_version' if built with HAVE_ICONV */
   int iconv_ver_num;
+  
+  /* This field was added in CURLVERSION_FOURTH */
+  const char *libssh2_version; /* human readable string */
+  
 } curl_version_info_data;
 
 #define CURL_VERSION_IPV6      (1<<0)  /* IPv6-enabled */
@@ -1553,6 +1613,7 @@
 #define CURL_VERSION_SSPI      (1<<11) /* SSPI is supported */
 #define CURL_VERSION_CONV      (1<<12) /* character conversions are
                                           supported */
+#define CURL_VERSION_LIBSSH2   (1<<13) /* LIBSSH2 options are present */
 
 /*
  * NAME curl_version_info()
Index: lib/Makefile.inc
===================================================================
RCS file: /cvsroot/curl/curl/lib/Makefile.inc,v
retrieving revision 1.13
diff -u -r1.13 Makefile.inc
--- lib/Makefile.inc	23 Sep 2006 19:07:20 -0000	1.13
+++ lib/Makefile.inc	27 Oct 2006 00:58:48 -0000
@@ -8,7 +8,7 @@
   content_encoding.c share.c http_digest.c md5.c http_negotiate.c	\
   http_ntlm.c inet_pton.c strtoofft.c strerror.c hostares.c hostasyn.c	\
   hostip4.c hostip6.c hostsyn.c hostthre.c inet_ntop.c parsedate.c	\
-  select.c gtls.c sslgen.c tftp.c splay.c strdup.c socks.c
+  select.c gtls.c sslgen.c tftp.c splay.c strdup.c socks.c sftp.c
 
 HHEADERS = arpa_telnet.h netrc.h file.h timeval.h base64.h hostip.h	\
   progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h	\
@@ -18,6 +18,6 @@
   share.h md5.h http_digest.h http_negotiate.h http_ntlm.h ca-bundle.h	\
   inet_pton.h strtoofft.h strerror.h inet_ntop.h curlx.h memory.h	\
   setup.h transfer.h select.h easyif.h multiif.h parsedate.h sslgen.h   \
-  gtls.h tftp.h sockaddr.h splay.h strdup.h setup_once.h socks.h
+  gtls.h tftp.h sockaddr.h splay.h strdup.h setup_once.h socks.h sftp.h
 
 
Index: lib/easy.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/easy.c,v
retrieving revision 1.88
diff -u -r1.88 easy.c
--- lib/easy.c	18 Oct 2006 21:05:47 -0000	1.88
+++ lib/easy.c	27 Oct 2006 00:58:49 -0000
@@ -715,6 +715,8 @@
   /* This is our prefered CA cert bundle since install time */
   data->set.ssl.CAfile = (char *)CURL_CA_BUNDLE;
 #endif
+  
+  data->set.libssh2_auth_types = CURLSSH2_AUTH_DEFAULT; /* defautls to any auth type */
 }
 
 #ifdef CURL_DOES_CONVERSIONS
Index: lib/sendf.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/sendf.c,v
retrieving revision 1.111
diff -u -r1.111 sendf.c
--- lib/sendf.c	23 Oct 2006 20:34:56 -0000	1.111
+++ lib/sendf.c	27 Oct 2006 00:58:53 -0000
@@ -45,6 +45,7 @@
 #include "sendf.h"
 #include "connect.h" /* for the Curl_sockerrno() proto */
 #include "sslgen.h"
+#include "sftp.h"
 
 #define _MPRINTF_REPLACE /* use the internal *printf() functions */
 #include <curl/mprintf.h>
@@ -326,9 +327,15 @@
   CURLcode retcode;
   int num = (sockfd == conn->sock[SECONDARYSOCKET]);
 
-  if (conn->ssl[num].use)
+  if (conn->ssl[num].use) {
     /* only TRUE if SSL enabled */
     bytes_written = Curl_ssl_send(conn, num, mem, len);
+  }
+#ifdef USE_LIBSSH2
+  else if (conn->scp_use) {
+    bytes_written = Curl_scp_send(conn, num, mem, len);
+  }
+#endif /* !USE_LIBSSH2 */
   else {
     if(conn->sec_complete)
       /* only TRUE if krb4 enabled */
@@ -499,9 +506,15 @@
   if(conn->ssl[num].use) {
     nread = Curl_ssl_recv(conn, num, conn->master_buffer, bytesfromsocket);
 
-    if(nread == -1)
+    if(nread == -1) {
       return -1; /* -1 from Curl_ssl_recv() means EWOULDBLOCK */
+    }
+  }
+#ifdef USE_LIBSSH2
+  else if (conn->scp_use) {
+    nread = Curl_scp_recv(conn, num, conn->master_buffer, bytesfromsocket);
   }
+#endif /* !USE_LIBSSH2 */
   else {
     if(conn->sec_complete)
       nread = Curl_sec_read(conn, sockfd, conn->master_buffer,
Index: lib/strerror.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/strerror.c,v
retrieving revision 1.38
diff -u -r1.38 strerror.c
--- lib/strerror.c	21 Oct 2006 11:32:07 -0000	1.38
+++ lib/strerror.c	27 Oct 2006 00:58:54 -0000
@@ -276,6 +276,154 @@
 
   case CURLE_CONV_REQD:
     return "caller must register CURLOPT_CONV_ callback options";
+    
+    /* Error Codes (defined by libssh2) */
+  case CURLE_LIBSSH2_ERROR_SOCKET_NONE:
+    return "LIBSSH2_ERROR_SOCKET_NONE";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_BANNER_NONE:
+    return "LIBSSH2_ERROR_BANNER_NONE";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_BANNER_SEND:
+    return "LIBSSH2_ERROR_BANNER_SEND";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_INVALID_MAC:
+    return "LIBSSH2_ERROR_INVALID_MAC";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_KEX_FAILURE:
+    return "LIBSSH2_ERROR_KEX_FAILURE";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_ALLOC:
+    return "LIBSSH2_ERROR_ALLOC";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_SOCKET_SEND:
+    return "LIBSSH2_ERROR_SOCKET_SEND";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE:
+    return "LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_TIMEOUT:
+    return "LIBSSH2_ERROR_TIMEOUT";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_HOSTKEY_INIT:
+    return "LIBSSH2_ERROR_HOSTKEY_INIT";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_HOSTKEY_SIGN:
+    return "LIBSSH2_ERROR_HOSTKEY_SIGN";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_DECRYPT:
+    return "LIBSSH2_ERROR_DECRYPT";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_SOCKET_DISCONNECT:
+    return "LIBSSH2_ERROR_SOCKET_DISCONNECT";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_PROTO:
+    return "LIBSSH2_ERROR_PROTO";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_PASSWORD_EXPIRED:
+    return "LIBSSH2_ERROR_PASSWORD_EXPIRED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_FILE:
+    return "LIBSSH2_ERROR_FILE";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_METHOD_NONE:
+    return "LIBSSH2_ERROR_METHOD_NONE";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED:
+    return "LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED:
+    return "LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_CHANNEL_OUTOFORDER:
+    return "LIBSSH2_ERROR_CHANNEL_OUTOFORDER";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_CHANNEL_FAILURE:
+    return "LIBSSH2_ERROR_CHANNEL_FAILURE";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED:
+    return "LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_CHANNEL_UNKNOWN:
+    return "LIBSSH2_ERROR_CHANNEL_UNKNOWN";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED:
+    return "LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED:
+    return "LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_CHANNEL_CLOSED:
+    return "LIBSSH2_ERROR_CHANNEL_CLOSED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_CHANNEL_EOF_SENT:
+    return "LIBSSH2_ERROR_CHANNEL_EOF_SENT";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_SCP_PROTOCOL:
+    return "LIBSSH2_ERROR_SCP_PROTOCOL";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_ZLIB:
+    return "LIBSSH2_ERROR_ZLIB";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_SOCKET_TIMEOUT:
+    return "LIBSSH2_ERROR_SOCKET_TIMEOUT";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_SFTP_PROTOCOL:
+    return "LIBSSH2_ERROR_SFTP_PROTOCOL";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_REQUEST_DENIED:
+    return "LIBSSH2_ERROR_REQUEST_DENIED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_METHOD_NOT_SUPPORTED:
+    return "LIBSSH2_ERROR_METHOD_NOT_SUPPORTED";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_INVAL:
+    return "LIBSSH2_ERROR_INVAL";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_INVALID_POLL_TYPE:
+    return "LIBSSH2_ERROR_INVALID_POLL_TYPE";
+    break;
+    
+  case CURLE_LIBSSH2_ERROR_PUBLICKEY_PROTOCOL:
+    return "LIBSSH2_ERROR_PUBLICKEY_PROTOCOL";
+    break;
+    
+  case CURLE_REMOTE_FILE_NOT_FOUND:
+    return "Remote file not found";
 
     /* error codes not used by current libcurl */
   case CURLE_URL_MALFORMAT_USER:
Index: lib/url.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/url.c,v
retrieving revision 1.557
diff -u -r1.557 url.c
--- lib/url.c	26 Oct 2006 11:15:25 -0000	1.557
+++ lib/url.c	27 Oct 2006 00:59:07 -0000
@@ -128,6 +128,7 @@
 #include "http.h"
 #include "file.h"
 #include "ldap.h"
+#include "sftp.h"
 #include "url.h"
 #include "connect.h"
 #include "inet_ntop.h"
@@ -538,6 +539,8 @@
     /* This no longer creates a connection cache here. It is instead made on
        the first call to curl_easy_perform() or when the handle is added to a
        multi stack. */
+    
+    data->set.libssh2_auth_types = CURLSSH2_AUTH_DEFAULT; /* defautls to any auth type */
 
     /* most recent connection is not yet defined */
     data->state.lastconnect = -1;
@@ -1665,7 +1668,25 @@
   case CURLOPT_SSL_SESSIONID_CACHE:
     data->set.ssl.sessionid = (bool)(0 != va_arg(param, long));
     break;
-
+    
+  case CURLOPT_SSH_AUTH_TYPES:
+    data->set.libssh2_auth_types = va_arg(param, long);
+    break;
+    
+  case CURLOPT_LIBSSH2_PUBLIC_KEYFILE:
+    /*
+     * Use this file instead of the $HOME/.ssh/id_dsa.pub file
+     */
+    data->set.libssh2_public_key = va_arg(param, char *);
+    break;
+    
+  case CURLOPT_LIBSSH2_PRIVATE_KEYFILE:
+    /*
+     * Use this file instead of the $HOME/.ssh/id_dsa file
+     */
+    data->set.libssh2_private_key = va_arg(param, char *);
+    break;
+    
   default:
     /* unknown tag and its companion, just ignore: */
     result = CURLE_FAILED_INIT; /* correct this */
@@ -3016,7 +3037,7 @@
     conn->curl_connecting = Curl_https_connecting;
     conn->curl_proto_getsock = Curl_https_getsock;
 
-#else /* USE_SS */
+#else /* USE_SSL */
     failf(data, LIBCURL_NAME
           " was built with SSL disabled, https: not supported!");
     return CURLE_UNSUPPORTED_PROTOCOL;
@@ -3206,7 +3227,22 @@
           " was built with TFTP disabled!");
 #endif
   }
-  else {
+  else if (strequal(conn->protostr, "SCP")) {
+#ifdef USE_LIBSSH2
+    conn->port = PORT_SSH;
+    conn->remote_port = PORT_SSH;
+    conn->protocol = PROT_SCP;
+    conn->curl_connect = Curl_scp_connect; /* ssh_connect? */
+    conn->curl_do = Curl_scp_do;
+    conn->curl_done = Curl_scp_done;
+    conn->curl_do_more = (Curl_do_more_func)NULL; /* TBD */
+#else
+    failf(data, LIBCUR_NAME
+		  " was built without LIBSSH2, scp: not supported!");
+    return CURLE_UNSUPPORTED_PROTOCOL;
+#endif
+}
+else {
     /* We fell through all checks and thus we don't support the specified
        protocol */
     failf(data, "Unsupported protocol: %s", conn->protostr);
@@ -3372,7 +3408,7 @@
   user[0] =0;   /* to make everything well-defined */
   passwd[0]=0;
 
-  if (conn->protocol & (PROT_FTP|PROT_HTTP)) {
+  if (conn->protocol & (PROT_FTP|PROT_HTTP|PROT_SCP)) {
     /* This is a FTP or HTTP URL, we will now try to extract the possible
      * user+password pair in a string like:
      * ftp://user:password@ftp.my.site:8021/README */
Index: lib/urldata.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/urldata.h,v
retrieving revision 1.306
diff -u -r1.306 urldata.h
--- lib/urldata.h	23 Oct 2006 20:34:56 -0000	1.306
+++ lib/urldata.h	27 Oct 2006 00:59:10 -0000
@@ -35,6 +35,7 @@
 #define PORT_DICT 2628
 #define PORT_LDAP 389
 #define PORT_TFTP 69
+#define PORT_SSH 22
 
 #define DICT_MATCH "/MATCH:"
 #define DICT_MATCH2 "/M:"
@@ -109,6 +110,11 @@
 # endif
 #endif
 
+#ifdef HAVE_LIBSSH2_H
+#include <libssh2.h>
+#include <libssh2_sftp.h>
+#endif /* HAVE_LIBSSH2_H */
+
 /* Download buffer size, keep it fairly big for speed reasons */
 #undef BUFSIZE
 #define BUFSIZE CURL_MAX_WRITE_SIZE
@@ -392,6 +398,21 @@
   ftpstate state; /* always use ftp.c:state() to change state! */
 };
 
+struct SCPPROTO {
+  curl_off_t *bytecountp;
+  char *user;
+  char *passwd;
+  char *path;			/* the path we operate on */
+  char *freepath;		/* pointer to the allocated block we must free, 
+                                   this might differ from the 'path' pointer */
+  char *errorstr;
+#ifdef USE_LIBSSH2
+  LIBSSH2_SESSION *scpSession; /* Secure Shell session */
+  LIBSSH2_CHANNEL *scpChannel; /* SCP channel handle */
+#endif /* USE_LIBSSH2 */
+};
+
+
 /****************************************************************************
  * FILE unique setup
  ***************************************************************************/
@@ -647,6 +668,7 @@
     struct FILEPROTO *file;
     void *telnet;        /* private for telnet.c-eyes only */
     void *generic;
+    struct SCPPROTO *scp;
   } proto;
 };
 
@@ -681,6 +703,7 @@
 #define PROT_FTPS    (1<<9)
 #define PROT_SSL     (1<<10) /* protocol requires SSL */
 #define PROT_TFTP    (1<<11)
+#define PROT_SCP     (1<<12)
 
   /* 'dns_entry' is the particular host we use. This points to an entry in the
      DNS cache and it will not get pruned while locked. It gets unlocked in
@@ -723,6 +746,8 @@
   struct ssl_connect_data ssl[2]; /* this is for ssl-stuff */
   struct ssl_config_data ssl_config;
 
+  bool scp_use;
+  
   struct ConnectBits bits;    /* various state-flags for this connection */
 
   /* These two functions MUST be set by the curl_connect() function to be
@@ -1250,6 +1275,10 @@
   bool ftp_skip_ip;      /* skip the IP address the FTP server passes on to
                             us */
   bool connect_only;     /* make connection, let application use the socket */
+  
+  long libssh2_auth_types;    /* allowed auth types */
+  char *libssh2_public_key;   /* the path to the public key file for authentication */
+  char *libssh2_private_key;  /* the path to the private key file for authentication */
 };
 
 struct Names {
Index: lib/version.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/version.c,v
retrieving revision 1.50
diff -u -r1.50 version.c
--- lib/version.c	15 Aug 2006 17:02:24 -0000	1.50
+++ lib/version.c	27 Oct 2006 00:59:10 -0000
@@ -45,6 +45,11 @@
 #include <iconv.h>
 #endif
 
+#ifdef USE_LIBSSH2
+#include <libssh2.h>
+#endif
+
+
 char *curl_version(void)
 {
   static char version[200];
@@ -88,7 +93,12 @@
   left -= len;
   ptr += len;
 #endif
-
+#ifdef USE_LIBSSH2
+  len = snprintf(ptr, left, " libssh2/%s", LIBSSH2_VERSION);
+  left -= len;
+  ptr += len;
+#endif
+  
   return version;
 }
 
@@ -125,6 +135,12 @@
   "ftps",
 #endif
 #endif
+  
+#ifdef USE_LIBSSH2
+  "sftp",
+  "scp",
+#endif
+  
   NULL
 };
 
@@ -170,6 +186,9 @@
 #if defined(CURL_DOES_CONVERSIONS)
   | CURL_VERSION_CONV
 #endif
+#ifdef USE_LIBSSH2
+  | CURL_VERSION_LIBSSH2
+#endif
   ,
   NULL, /* ssl_version */
   0,    /* ssl_version_num, this is kept at zero */
@@ -179,6 +198,7 @@
   0,    /* c-ares version numerical */
   NULL, /* libidn version */
   0,    /* iconv version */
+  NULL, /* libssh2 version */
 };
 
 curl_version_info_data *curl_version_info(CURLversion stamp)
@@ -216,6 +236,10 @@
   version_info.iconv_ver_num = -1;
 #endif /* _LIBICONV_VERSION */
 #endif
+  
+#ifdef USE_LIBSSH2
+  version_info.libssh2_version = LIBSSH2_SSH_BANNER;
+#endif
 
   (void)stamp; /* avoid compiler warnings, we don't use this */
 
