]> granicus.if.org Git - curl/commitdiff
SCP: send large files properly with new enough libssh2
authorDaniel Stenberg <daniel@haxx.se>
Wed, 4 Aug 2010 15:23:38 +0000 (17:23 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 4 Aug 2010 16:29:13 +0000 (18:29 +0200)
libssh2 1.2.6 and later handle >32bit file sizes properly even on 32bit
architectures and we make sure to use that ability.

Reported by: Mikael Johansson
Bug: http://curl.haxx.se/mail/lib-2010-08/0052.html

configure.ac
lib/ssh.c
lib/ssh.h

index 633f9e49a3a5bc513942bf79d675f336e1e1a251..fe57875d94e32f0917d71d657584b3a61ed4976d 100644 (file)
@@ -1984,7 +1984,9 @@ if test X"$OPT_LIBSSH2" != Xno; then
 
        dnl libssh2_version is a post 1.0 addition
        dnl libssh2_init and libssh2_exit were added in 1.2.5
-       AC_CHECK_FUNCS( libssh2_version libssh2_init libssh2_exit)
+       dnl libssh2_scp_send64 was added in 1.2.6
+       AC_CHECK_FUNCS( libssh2_version libssh2_init libssh2_exit \
+                       libssh2_scp_send64 )
 
        LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DIR_SSH2"
        export LD_LIBRARY_PATH
index 67995058a53bdef073cbe730019c0de18af90e56..fe8c16a2428212228437a9450143c82cb76e280b 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -485,6 +485,17 @@ static int sshkeycallback(CURL *easy,
 #define SFTP_SEEK(x,y) libssh2_sftp_seek(x, (size_t)y)
 #endif
 
+/*
+ * Earlier libssh2 versions didn't do SCP properly beyond 32bit sizes on 32bit
+ * architectures so we check of the necessary function is present.
+ */
+#ifdef HAVE_LIBSSH2_SCP_SEND64
+#define SCP_SEND(a,b,c,d) libssh2_scp_send_ex(a, b, (int)(c), (size_t)d, 0, 0)
+#else
+#define SCP_SEND(a,b,c,d) libssh2_scp_send64(a, b, (int)(c),            \
+                                             (libssh2_uint64_t)d, 0, 0)
+#endif
+
 /*
  * ssh_statemach_act() runs the SSH state machine as far as it can without
  * blocking and without reaching the end.  The data the pointer 'block' points
@@ -2083,9 +2094,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
        * directory in the path.
        */
       sshc->ssh_channel =
-        libssh2_scp_send_ex(sshc->ssh_session, sftp_scp->path,
-                            (int)(data->set.new_file_perms),
-                            (size_t)data->set.infilesize, 0, 0);
+        SCP_SEND(sshc->ssh_session, sftp_scp->path, data->set.new_file_perms,
+                 data->set.infilesize);
       if(!sshc->ssh_channel) {
         if(libssh2_session_last_errno(sshc->ssh_session) ==
            LIBSSH2_ERROR_EAGAIN) {
index b92b5c03bb77d2475116374d6a1ed479b364f783..d0882e956d336e2776c62d40a79892a79714babc 100644 (file)
--- a/lib/ssh.h
+++ b/lib/ssh.h
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -158,6 +158,12 @@ struct ssh_conn {
 #  undef HAVE_LIBSSH2_SFTP_SEEK64
 #endif
 
+#if defined(LIBSSH2_VERSION_NUM) && (LIBSSH2_VERSION_NUM >= 0x010206)
+#  define HAVE_LIBSSH2_SCP_SEND64 1
+#else
+#  undef HAVE_LIBSSH2_SFTP_SEEK64
+#endif
+
 
 extern const struct Curl_handler Curl_handler_scp;
 extern const struct Curl_handler Curl_handler_sftp;