Merge branch '2.0'

This commit is contained in:
terrafrost 2019-03-03 18:42:47 -06:00
commit 496fcd18cd

View File

@ -113,11 +113,11 @@ class SFTP extends SSH2
* The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support
* concurrent actions, so it's somewhat academic, here.
*
* @var int
* @var boolean
* @see self::_send_sftp_packet()
* @access private
*/
private $request_id = false;
private $use_request_id = false;
/**
* The Packet Type
@ -254,6 +254,15 @@ class SFTP extends SSH2
*/
private $canonicalize_paths = true;
/**
* Request Buffers
*
* @see self::_get_sftp_packet()
* @var array
* @access private
*/
var $requestBuffer = array();
/**
* Default Constructor.
*
@ -529,7 +538,7 @@ class SFTP extends SSH2
}
*/
$this->request_id = 1;
$this->use_request_id = true;
/*
A Note on SFTPv4/5/6 support:
@ -2240,7 +2249,7 @@ class SFTP extends SSH2
$packet_size = $length > 0 ? min($this->max_sftp_packet, $length - $read) : $this->max_sftp_packet;
$packet = pack('Na*N3', strlen($handle), $handle, $tempoffset / 4294967296, $tempoffset, $packet_size);
if (!$this->send_sftp_packet(NET_SFTP_READ, $packet)) {
if (!$this->send_sftp_packet(NET_SFTP_READ, $packet, $i)) {
if ($fclose_check) {
fclose($fp);
}
@ -2255,15 +2264,17 @@ class SFTP extends SSH2
break;
}
$packets_sent = $i - 1;
$clear_responses = false;
while ($i > 0) {
$i--;
if ($clear_responses) {
$this->get_sftp_packet();
$this->get_sftp_packet($packets_sent - $i);
continue;
} else {
$response = $this->get_sftp_packet();
$response = $this->get_sftp_packet($packets_sent - $i);
}
switch ($this->packet_type) {
@ -2989,10 +3000,10 @@ class SFTP extends SSH2
* @return bool
* @access private
*/
private function send_sftp_packet($type, $data)
private function send_sftp_packet($type, $data, $request_id = 1)
{
$packet = $this->request_id !== false ?
pack('NCNa*', strlen($data) + 5, $type, $this->request_id, $data) :
$packet = $this->use_request_id ?
pack('NCNa*', strlen($data) + 5, $type, $request_id, $data) :
pack('NCa*', strlen($data) + 1, $type, $data);
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
@ -3030,8 +3041,15 @@ class SFTP extends SSH2
* @return string
* @access private
*/
private function get_sftp_packet()
private function get_sftp_packet($request_id = null)
{
if (isset($request_id) && isset($this->requestBuffer[$request_id])) {
$this->packet_type = $this->requestBuffer[$request_id]['packet_type'];
$temp = $this->requestBuffer[$request_id]['packet'];
unset($this->requestBuffer[$request_id]);
return $temp;
}
$this->curTimeout = false;
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
@ -3071,8 +3089,8 @@ class SFTP extends SSH2
$this->packet_type = ord(Strings::shift($this->packet_buffer));
if ($this->request_id !== false) {
Strings::shift($this->packet_buffer, 4); // remove the request id
if ($this->use_request_id) {
extract(unpack('Npacket_id', 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
@ -3095,6 +3113,14 @@ class SFTP extends SSH2
}
}
if (isset($request_id) && $this->use_request_id && $packet_id != $request_id) {
$this->requestBuffer[$packet_id] = array(
'packet_type' => $this->packet_type,
'packet' => $packet
);
return $this->_get_sftp_packet($request_id);
}
return $packet;
}