data exceeds window size

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

data exceeds window size

Postby xkeywee » Wed Jul 03, 2013 8:49 am

Hi

I have a problem uploading files to one SFTP server, it will randomly upload the files but most of the time I get "data exceeds window size".

I can upload to another SFTP server without any problem or errors.

The serve I am trying to send to is: Titan FTP Server version 7.11 build 879.
I get Server Identification: SSH-2.0-1.82 sshlib: sshlibSrSshServer 1.00
I am using: PHPSecLib 0.3.5
The file is :PDF file - 139.70 KB (143,057 bytes)

I get these error messages
PHP Notice: Connection closed by server in /phpseclib0.3.5/Net/SSH2.php on line 2593
PHP Notice: Expected SSH_FXP_STATUS in /phpseclib0.3.5/Net/SFTP.php on line 1602
PHP Notice: Connection closed prematurely in/phpseclib0.3.5/Net/SSH2.php on line 2746

This is a basic test the code I am using
<?php
include('Net/SFTP.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
$sftp = new Net_SFTP('xxx.xxx.xxx.xxx');
if (!$sftp->login('uuuuuu', 'pppppp')) {
exit('Login Failed');
}
if (!$sftp->chdir("ps_test")) {
$sftp->mkdir("ps_test");
}
$file_name = 'test.pdf';
$source_file = '/home/temp/test.pdf';
$sftp->put($file_name, $source_file, NET_SFTP_LOCAL_FILE);
print $sftp->getLog();
$sftp->disconnect();
?>

I will attach the SSH log

I have read all the other posts and tried everything that has been suggested but no luck, any assistance would be greatly appreciated.

Thanks
Greg
Attachments
pstest-dev-03-07-082805.txt
SSH Log
(696.1 KiB) Downloaded 115 times
xkeywee
Traveler
 
Posts: 6
Joined: Wed Jul 03, 2013 8:33 am

Re: data exceeds window size

Postby TerraFrost » Sun Jul 07, 2013 9:13 pm

Sorry about the delay - I was on vacation.

Anyway, from your logs:

Code: Select all
<- NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION (since last: 0.0259, network: 0.0258s)
00000000  00:00:00:02:00:00:00:00:00:00:40:00:00:00:8c:00  ..........@.....

Here's how that breaks down:

Code: Select all
recipient channel:   00:00:00:02
sender channel:      00:00:00:00
initial window size: 00:00:40:00
maximum packet size: 00:00:8c:00

It's a bit weird that the servers window size is smaller than the packet size. For packets being sent from the client to the server phpseclib uses the max window size of 0x7FFFFFFF and a max packet size of 0x4000. ie. the window size is considerably larger than the packet size.

I don't know how to duplicate that so it's difficult for me to test any potential fix myself but, none-the-less, try this branch on github:

https://github.com/terrafrost/phpseclib/tree/xkeywee

If that doesn't help let me know and there are other things we can try.

Thanks!
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: data exceeds window size

Postby xkeywee » Mon Jul 08, 2013 4:59 am

Hi

Thanks but it still didn't work

I got the following errors
PHP Notice: fputs(): send of 4 bytes failed with errno=32 Broken pipe in /phpseclib/Net/SSH2.php on line 2840
PHP Notice: fputs(): send of 36 bytes failed with errno=32 Broken pipe in /phpseclib/Net/SSH2.php on line 2840

I have attached the log file in case that helps

File size on the server is still 12kb

Appreciate your assistance.
Greg
Attachments
pstest-dev-08-07-045406.txt
(668.58 KiB) Downloaded 136 times
xkeywee
Traveler
 
Posts: 6
Joined: Wed Jul 03, 2013 8:33 am

Re: data exceeds window size

Postby TerraFrost » Sun Jul 14, 2013 9:37 am

The latest Git version should fix this.

Thank you for your assistance in this matter!!
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: data exceeds window size

Postby xkeywee » Mon Jul 15, 2013 12:17 am

Thank you so much, works perfectly.

I have just made a donation as a small gesture of my appreciation.

Thanks again.
Greg
xkeywee
Traveler
 
Posts: 6
Joined: Wed Jul 03, 2013 8:33 am

Re: data exceeds window size

Postby TerraFrost » Mon Jul 15, 2013 10:55 pm

:D Thanks! :D
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: data exceeds window size

Postby xkeywee » Tue Jul 16, 2013 8:32 am

Hi

I spoke to soon.

It works fine as long as the file is less then 5mb, once the file gets over 5mb it just hangs.

Hopefully you might know what is causing this.

Many thanks
Greg
xkeywee
Traveler
 
Posts: 6
Joined: Wed Jul 03, 2013 8:33 am

Re: data exceeds window size

Postby xkeywee » Wed Jul 17, 2013 12:43 am

Forgot to mention we are getting multiple of these errors

PHP Notice: Uninitialized string offset: 0 in /phpseclib/Net/SSH2.php on line 2521

Thanks
Greg
xkeywee
Traveler
 
Posts: 6
Joined: Wed Jul 03, 2013 8:33 am

Re: data exceeds window size

Postby TerraFrost » Thu Jul 18, 2013 4:30 am

I just made a commit that I think should fix this. If you could test that'd be great. Thanks!
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: data exceeds window size

Postby xkeywee » Thu Jul 18, 2013 6:30 am

Fantastic!!!!

Works Great!!

Thanks Again!!
xkeywee
Traveler
 
Posts: 6
Joined: Wed Jul 03, 2013 8:33 am

Re: data exceeds window size

Postby TerraFrost » Sat Jul 20, 2013 9:25 pm

I'm thinking about making a change relating to the window size that I was wondering if you could test for me and tell me if it works for you:

In particular, can you replace your _send_channel_packet() method in SSH2.php with this one and tell me if it works?:

Code: Select all
    /**
     * Sends channel data
     *
     * Spans multiple SSH_MSG_CHANNEL_DATAs if appropriate
     *
     * @param Integer $client_channel
     * @param String $data
     * @return Boolean
     * @access private
     */
    function _send_channel_packet($client_channel, $data)
    {
        // The maximum amount of data allowed is determined by the maximum
        // packet size for the channel, and the current window size, whichever
        // is smaller.
        $max_size = min(
            $this->packet_size_client_to_server[$client_channel],
            $this->window_size_client_to_server[$client_channel]
        ) - 4;
        while (strlen($data) > $max_size) {
            $packet = pack('CN2a*',
                NET_SSH2_MSG_CHANNEL_DATA,
                $this->server_channels[$client_channel],
                $max_size,
                $this->_string_shift($data, $max_size)
            );

            $this->window_size_client_to_server[$client_channel]-= $max_size + 4;

            if (!$this->_send_binary_packet($packet)) {
                return false;
            }

            if ($max_size == $this->window_size_client_to_server[$client_channel] - 4) {
                $this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
                // using an invalid channel will let the buffers be built up for the valid channels
                $this->_get_channel_packet(-1);
                $this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
                $max_size = min(
                    $this->packet_size_client_to_server[$client_channel],
                    $this->window_size_client_to_server[$client_channel]
                ) - 4;
            }
        }

        if (strlen($data) >= $this->window_size_client_to_server[$client_channel] - 4) {
            $this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
            $this->_get_channel_packet(-1);
            $this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
        }

        $this->window_size_client_to_server[$client_channel]-= strlen($data) + 4;

        return $this->_send_binary_packet(pack('CN2a*',
            NET_SSH2_MSG_CHANNEL_DATA,
            $this->server_channels[$client_channel],
            strlen($data),
            $data));
    }

I discuss the motivation for this change in more detail here:

viewtopic.php?p=392092#p392092

Thanks!
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am


Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 1 guest

cron