Subject: Re: libssh2_sftp_write fails with return code -1

Re: libssh2_sftp_write fails with return code -1

From: Mark Riordan <>
Date: Sun, 31 Oct 2010 18:56:08 -0500

>> Yesterday (2010-10-28) I did a "git" from the repository and rebuilt my
>> program with the newest libssh2. Unfortunately, uploads now fail on the
>> first call to libssh2_sftp_write, whereas with 1.2.7, the test program
>> generally worked.

> Great, we need testing of the current git version to make it run properly!
> Can you please build a debug-enabled libssh2 and call
> libssh2_trace(session, ~0); after you've called
> session_init() and provide the log output?

After checking with git to make sure my libssh2 source was up-to-date
(it still was), I recompiled libssh2 with LIBSSH2DEBUG defined.
I then enhanced my program to take a debug parameter, which causes it to
libssh2_trace(session, ~0).

Alas, when debug is on, the uploads succeed. I tried several times.
I have a 649 MB trace log, but I won't upload it, since it doesn't show
any failures.

With debug off, transfers of my large test file fail, more or less
as before.
Though with the version of libssh2 compiled with LIBSSH2DEBUG defined,
sometimes 100 or more libssh2_sftp_write calls will succeed before one
returns -1.
The failures do not always occur at the same point, even though I'm
using the same test file each time.

I've noticed that the average number of bytes sent per call of
libssh2_sftp_write is smaller with the LIBSSH2DEBUG version,
even if debug is turned off.

I put the source to my program, plus Windows executable, at:


Received on 2010-11-01