Net_SSH2::_send_channel_packet PHP Method

_send_channel_packet() public method

Spans multiple SSH_MSG_CHANNEL_DATAs if appropriate
public _send_channel_packet ( integer $client_channel, string $data ) : boolean
$client_channel integer
$data string
return boolean
    function _send_channel_packet($client_channel, $data)
    {
        while (strlen($data)) {
            if (!$this->window_size_client_to_server[$client_channel]) {
                $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;
            }
            /* The maximum amount of data allowed is determined by the maximum
               packet size for the channel, and the current window size, whichever
               is smaller.
                 -- http://tools.ietf.org/html/rfc4254#section-5.2 */
            $max_size = min($this->packet_size_client_to_server[$client_channel], $this->window_size_client_to_server[$client_channel]);
            $temp = $this->_string_shift($data, $max_size);
            $packet = pack('CN2a*', NET_SSH2_MSG_CHANNEL_DATA, $this->server_channels[$client_channel], strlen($temp), $temp);
            $this->window_size_client_to_server[$client_channel] -= strlen($temp);
            if (!$this->_send_binary_packet($packet)) {
                return false;
            }
        }
        return true;
    }

Usage Example

Example #1
0
 public function write($data)
 {
     return $this->ssh->_send_channel_packet(NET_SSH2_CHANNEL_EXEC, $data);
 }