Subject: Re: libssh2_sftp_read reads a number of bytes smaller than both the file size and the specified buffer size

Re: libssh2_sftp_read reads a number of bytes smaller than both the file size and the specified buffer size

From: Adam Craig <adamgcraig_at_accessnoexcuse.org>
Date: Tue, 3 Apr 2012 16:19:07 -0700

On 4/3/12, Peter Stuge <peter_at_stuge.se> wrote:
> Adam Craig wrote:
>> > This sounds like the expected behaviour of libssh2's pipelined SFTP
>> > architecture. The return value doesn't have to correspond to the
>> > amount uploaded on _that_ call as long as the overall total is
>> > correct. The last call that doesn't appear to do anything allows
>> > libssh2 to do some housekeeping.
>>
>> What do you mean by the "overall total?"
>
> Number of bytes transfered once libssh2 returns 0 to indicate
> completion.
>
Do you mean the number of bytes transferred in that function call,
with that file handle, with that session handle, or something else?

>
>> If I upload a file of 200K all in one call to libssh2_sftp_write and
>> it returns 30K when it actually uploaded all 200K, what does the 30K
>> return value mean?
>
> It means that libssh2 has sent some data but not all, and you need to
> call libssh2 again.
That is what I thought it meant, but, even if I do not call _write
again, all 200K bytes show up in the file on the server.

>
>
>> > I'm not sure why yours are limited to 2K but I believe this is
>> > negotiated with the server (jump in here guys if I'm wrong) so
>> > it's possible your server is refusing to send bigger packets.
>
> I don't think this is negotiable.
>
>
>> That was my first guess, and it may be the case. After looking at
>> the documentation for the server-side SFTP tool and not finding any
>> information about a maximum packet size, I decided to look into
>> whether it was an issue with Libssh2.
>>
>> Documentation I read for the SFTP server utility to which the app
>> is connecting:
>> http://www.openbsd.org/cgi-bin/man.cgi?query=sftp-server&sektion=8
>
> In any case, OpenSSH sftp-server has pretty much zero tunables.
>
> Is the server OpenBSD, or OpenSSH portable on some other unix?
>
The server is Red Hat. Would you recommend trying a different SFTP
server utility?

Adam

>
> //Peter
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
>
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-04-04