Checking why the packet length is to big I found that the 4 bytes received from the server have the too big value.
line 156 in sftp.c rc = libssh2_channel_read_ex(channel, 0, (char *) buffer, 4); ..... packet_len = libssh2_ntohu32(buffer); _libssh2_debug(session, LIBSSH2_DBG_SFTP, "Data begin - Packet Length: %lu", packet_len); if (packet_len > LIBSSH2_SFTP_PACKET_MAXLEN) { libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, "SFTP packet too large", 0); return -1; } The server can only answer with a size which was set before by the client (otherwise it is a server bug). As far as I understand the buffer size is send as part of the SSH_FXP_READ request which is set in sftp.c in line 1025. Here the max buffer is set to buffer_maxlen (the user set value), but I think it can't be more than bytes_requested = LIBSSH2_SFTP_PACKET_MAXLEN - 10 Markus if (sftp->read_state == libssh2_NB_state_allocated) { libssh2_htonu32(s, packet_len - 4); s += 4; *(s++) = SSH_FXP_READ; request_id = sftp->request_id++; libssh2_htonu32(s, request_id); s += 4; libssh2_htonu32(s, handle->handle_len); s += 4; memcpy(s, handle->handle, handle->handle_len); s += handle->handle_len; libssh2_htonu64(s, handle->u.file.offset); s += 8; libssh2_htonu32(s, buffer_maxlen); s += 4; sftp->read_state = libssh2_NB_state_created; } "Markus Moeller" <hua...@moeller.plus.com> wrote in message news:gi0gi8$lk...@ger.gmane.org... > Since I experienced a similar issue when using curl with sftp I run the > sample with some debug and got to the point where in libssh2_sftp.h the > maximal packet length is defined as 40000. Where does this maximum come > from > ? Is it an arbitrary value or somewhere defined in the ssh/sftp protocol > ? > > Thank you > Markus > > #define LIBSSH2_SFTP_VERSION 3 > #define LIBSSH2_SFTP_PACKET_MAXLEN 40000 > > > trying buffer size 39990 > [libssh2] SFTP Subsystem: Reading 39990 bytes from SFTP handle > [libssh2] SFTP Subsystem: Requesting 39990 bytes from SFTP handle > [libssh2] Connection: Writing 29 bytes on channel 0/0, stream #0 > [libssh2] Connection: Sending 29 bytes on channel 0/0, stream_id=0 > [libssh2] SFTP Subsystem: _requirev(): Initialize timeout > [libssh2] SFTP Subsystem: Waiting for packet > [libssh2] SFTP Subsystem: Asking for 103 packet > [libssh2] SFTP Subsystem: Asking for 101 packet > [libssh2] SFTP Subsystem: Waiting for packet > [libssh2] Connection: Attempting to read 4 bytes from channel 0/0 stream > #0 > [libssh2] Transport: Packet type 94 received, length=16393 > [libssh2] Connection: 16384 bytes received for channel 0/0 stream #0 > [libssh2] Connection: Reading 4 of buffered data from 0/0/0 > [libssh2] SFTP Subsystem: Data begin - Packet Length: 39999 > [libssh2] Connection: Attempting to read 39999 bytes from channel 0/0 > stream > #0 > [libssh2] Transport: Packet type 94 received, length=16393 > [libssh2] Connection: 16384 bytes received for channel 0/0 stream #0 > [libssh2] Transport: Packet type 94 received, length=7244 > [libssh2] Connection: 7235 bytes received for channel 0/0 stream #0 > [libssh2] Connection: Reading 16380 of buffered data from 0/0/0 > [libssh2] Connection: Unlinking empty packet buffer from channel 0/0 > [libssh2] Connection: Adjusting window 16384 bytes for data flushed from > channel 0/0 > [libssh2] Connection: Reading 16384 of buffered data from 0/0/0 > [libssh2] Connection: Unlinking empty packet buffer from channel 0/0 > [libssh2] Connection: Adjusting window 16384 bytes for data flushed from > channel 0/0 > [libssh2] Connection: Reading 7235 of buffered data from 0/0/0 > [libssh2] Connection: Unlinking empty packet buffer from channel 0/0 > [libssh2] Connection: Adjusting window 7235 bytes for data flushed from > channel 0/0 > [libssh2] SFTP Subsystem: Received packet 103 > [libssh2] SFTP Subsystem: Asking for 103 packet > [libssh2] SFTP Subsystem: 39990 bytes returned > trying buffer size 39991 > [libssh2] SFTP Subsystem: Reading 39991 bytes from SFTP handle > [libssh2] SFTP Subsystem: Requesting 39990 bytes from SFTP handle > [libssh2] Connection: Writing 29 bytes on channel 0/0, stream #0 > [libssh2] Connection: Sending 29 bytes on channel 0/0, stream_id=0 > [libssh2] SFTP Subsystem: _requirev(): Initialize timeout > [libssh2] SFTP Subsystem: Waiting for packet > [libssh2] SFTP Subsystem: Asking for 103 packet > [libssh2] SFTP Subsystem: Asking for 101 packet > [libssh2] SFTP Subsystem: Waiting for packet > [libssh2] Connection: Attempting to read 4 bytes from channel 0/0 stream > #0 > [libssh2] Transport: Packet type 94 received, length=16393 > [libssh2] Connection: 16384 bytes received for channel 0/0 stream #0 > [libssh2] Connection: Reading 4 of buffered data from 0/0/0 > [libssh2] SFTP Subsystem: Data begin - Packet Length: 40000 > [libssh2] Connection: Attempting to read 40000 bytes from channel 0/0 > stream > #0 > [libssh2] Transport: Packet type 94 received, length=16393 > [libssh2] Connection: 16384 bytes received for channel 0/0 stream #0 > [libssh2] Transport: Packet type 94 received, length=7245 > [libssh2] Connection: 7236 bytes received for channel 0/0 stream #0 > [libssh2] Connection: Reading 16380 of buffered data from 0/0/0 > [libssh2] Connection: Unlinking empty packet buffer from channel 0/0 > [libssh2] Connection: Adjusting window 16384 bytes for data flushed from > channel 0/0 > [libssh2] Connection: Reading 16384 of buffered data from 0/0/0 > [libssh2] Connection: Unlinking empty packet buffer from channel 0/0 > [libssh2] Connection: Adjusting window 16384 bytes for data flushed from > channel 0/0 > [libssh2] Connection: Reading 7236 of buffered data from 0/0/0 > [libssh2] Connection: Unlinking empty packet buffer from channel 0/0 > [libssh2] Connection: Adjusting window 7236 bytes for data flushed from > channel 0/0 > [libssh2] SFTP Subsystem: Received packet 103 > [libssh2] SFTP Subsystem: Asking for 103 packet > [libssh2] SFTP Subsystem: 39991 bytes returned > trying buffer size 39992 > [libssh2] SFTP Subsystem: Reading 39992 bytes from SFTP handle > [libssh2] SFTP Subsystem: Requesting 39990 bytes from SFTP handle > [libssh2] Connection: Writing 29 bytes on channel 0/0, stream #0 > [libssh2] Connection: Sending 29 bytes on channel 0/0, stream_id=0 > [libssh2] SFTP Subsystem: _requirev(): Initialize timeout > [libssh2] SFTP Subsystem: Waiting for packet > [libssh2] SFTP Subsystem: Asking for 103 packet > [libssh2] SFTP Subsystem: Asking for 101 packet > [libssh2] SFTP Subsystem: Waiting for packet > [libssh2] Connection: Attempting to read 4 bytes from channel 0/0 stream > #0 > [libssh2] Transport: Packet type 94 received, length=16393 > [libssh2] Connection: 16384 bytes received for channel 0/0 stream #0 > [libssh2] Connection: Reading 4 of buffered data from 0/0/0 > [libssh2] SFTP Subsystem: Data begin - Packet Length: 40001 > [libssh2] Failure Event: -25 - SFTP packet too large > [libssh2] Failure Event: -30 - Timeout waiting for status message > libssh2_sftp_read() failed > > > > > > > > "Alexander Lamaison" <sw...@lammy.co.uk> wrote > in message > news:9c3275a90811271540y2f601286w7ce0c089e6ed5...@mail.gmail.com... >> 2008/11/27 Daniel Stenberg <dan...@haxx.se>: >>>> Does anyone have any ideas what might be happening? I'm afraid I >>>> haven't >>>> got a clue where to start debugging this. >> >> Firstly, apologies for my stupidity. The part of my previous email >> about the speed-up was because I forgot to call >> libssh2_sftp_seek(handle, 0) inside the loop so eventually it ran off >> the end of the file. However the overall question of why there is a >> threshold for the buffer size of 39992, still applies. >> >>> Can you provide us with the source for a full app that reproduces the >>> problem? >>> >>> Preferably as small as possible, and without too much windows-specific >>> code... >> >> I have attached the code you ask. Most of the window-specific stuff >> is gone but I may have missed something. Also, I'm not sure what >> should be included in the place of Winsock for unix. Maybe nothing. >> >> Many thanks. >> >> Alex >> > > > -------------------------------------------------------------------------------- > > >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's >> challenge >> Build the coolest Linux based applications with Moblin SDK & win great >> prizes >> Grand prize is a trip for two to an Open Source event anywhere in the >> world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > > -------------------------------------------------------------------------------- > > >> _______________________________________________ >> libssh2-devel mailing list >> libssh2-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/libssh2-devel >> > > > > ------------------------------------------------------------------------------ > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, > Nevada. > The future of the web can't happen without you. Join us at MIX09 to help > pave the way to the Next Web now. Learn more and register at > http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ _______________________________________________ libssh2-devel mailing list libssh2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libssh2-devel