Subject: [libssh2] Problems connecting to remote server in libssh2_session_startup()

[libssh2] Problems connecting to remote server in libssh2_session_startup()

From: Bo Granlund <>
Date: Thu, 8 Mar 2007 02:12:07 +0200


I'm new to this list so please bear with me. :)

I'm trying to use the most current libssh2 version from CVS. I have an
download from a month ago and then also a current (checked out a few hours
ago). I also have this tester program (attachment, scp.c), which fails to
work at all with the current version of the libssh2 distribution. I've
traced it down to libssh2_session_startup(session, sock);. This function
blocks the program for a minute or so (I didn't do any measurements, sorry),
and fails with the error message:

Failure establishing SSH session: -5

Now, I tried this too with libssh2 0.14, and it wen't as far as
libssh2_scp_send(), and actually started to send the file when I applied
this modest patch to libssh2/src/scp.c:

--- orig.libssh2-0.14/src/scp.c 2006-03-02 03:07:20.000000000 +0200
+++ libssh2-0.14/src/scp.c 2007-03-08 00:32:23.000000000 +0200
@@ -378,12 +378,14 @@
       LIBSSH2_FREE(session, command);

+#if 0
        /* Wait for ACK */
        if ((libssh2_channel_read(channel, response, 1) <= 0) || +(response[0] != 0)) {
                libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, +"Invalid ACK response from remote", 0);
                return NULL;

        /* Send mtime and atime to be used for file */
        if (mtime || atime) {

Now my scp.c (the attachment) works just fine with this patch applied to
0.14 and the program linked against it.

Now the thing is, that in CVS versions of the library it fails to receive
input from the server for some unknown reason. This is what I get in strace:

open("/dev/urandom", O_RDONLY|O_NONBLOCK|O_NOCTTY) = 4
fstat(4, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 9), ...}) = 0
select(5, [4], NULL, NULL, {0, 10000}) = 1 (in [4], left {0, 10000})
read(4, "%e\252rHK\v\325\205\225\246\352\22,AN\344\247\23\214\257"..., 32) =
close(4) = 0
getuid() = 1000
sendto(3, "\0\0\0024\5\24=\257\357\245\302\3302\320\3538k\260\211"..., 568,
recvfrom(3, "\0\0\2\344\n\24J\314\371\222\31K\233\250\33\234\27\336"...,

... and then there is no response to it whatsoever.

Am I doing something terribly wrong here? I'm very sorry if this is a FAQ,
if it is, just reply with a polite "RTFM" to me and I'll keep on digging
with google. :)

kind wishes,
Bo Granlund

P.S. I don't know if I'm on the mailinglist or not, sourceforge list servers
are acting a bit weird, so I would really appreciate it if you could include in the response you write. Thank you.

Take Surveys. Earn Cash. Influence the Future of IT
Join's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash

libssh2-devel mailing list

Received on 2007-03-08