phpseclib\Net\SFTP::_get_sftp_packet PHP Method

_get_sftp_packet() public method

See '6. General Packet Format' of draft-ietf-secsh-filexfer-13 for more info. Incidentally, the number of SSH_MSG_CHANNEL_DATA messages has no bearing on the number of SFTP packets present. There can be one SSH_MSG_CHANNEL_DATA messages containing two SFTP packets or there can be two SSH_MSG_CHANNEL_DATA messages containing one SFTP packet.
See also: self::_send_sftp_packet()
public _get_sftp_packet ( ) : string
return string
    function _get_sftp_packet()
    {
        $this->curTimeout = false;
        $start = strtok(microtime(), ' ') + strtok('');
        // http://php.net/microtime#61838
        // SFTP packet length
        while (strlen($this->packet_buffer) < 4) {
            $temp = $this->_get_channel_packet(self::CHANNEL);
            if (is_bool($temp)) {
                $this->packet_type = false;
                $this->packet_buffer = '';
                return false;
            }
            $this->packet_buffer .= $temp;
        }
        if (strlen($this->packet_buffer) < 4) {
            return false;
        }
        extract(unpack('Nlength', Strings::shift($this->packet_buffer, 4)));
        $tempLength = $length;
        $tempLength -= strlen($this->packet_buffer);
        // SFTP packet type and data payload
        while ($tempLength > 0) {
            $temp = $this->_get_channel_packet(self::CHANNEL);
            if (is_bool($temp)) {
                $this->packet_type = false;
                $this->packet_buffer = '';
                return false;
            }
            $this->packet_buffer .= $temp;
            $tempLength -= strlen($temp);
        }
        $stop = strtok(microtime(), ' ') + strtok('');
        $this->packet_type = ord(Strings::shift($this->packet_buffer));
        if ($this->request_id !== false) {
            Strings::shift($this->packet_buffer, 4);
            // remove the request id
            $length -= 5;
            // account for the request id and the packet type
        } else {
            $length -= 1;
            // account for the packet type
        }
        $packet = Strings::shift($this->packet_buffer, $length);
        if (defined('NET_SFTP_LOGGING')) {
            $packet_type = '<- ' . $this->packet_types[$this->packet_type] . ' (' . round($stop - $start, 4) . 's)';
            if (NET_SFTP_LOGGING == self::LOG_REALTIME) {
                echo "<pre>\r\n" . $this->_format_log(array($packet), array($packet_type)) . "\r\n</pre>\r\n";
                flush();
                ob_flush();
            } else {
                $this->packet_type_log[] = $packet_type;
                if (NET_SFTP_LOGGING == self::LOG_COMPLEX) {
                    $this->packet_log[] = $packet;
                }
            }
        }
        return $packet;
    }