mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-28 12:10:59 +00:00
Implement parallel download
This commit is contained in:
parent
b69fa7f2a9
commit
11a539bcbd
@ -2064,16 +2064,42 @@ class SFTP extends SSH2
|
|||||||
|
|
||||||
$start = $offset;
|
$start = $offset;
|
||||||
$size = $this->max_sftp_packet < $length || $length < 0 ? $this->max_sftp_packet : $length;
|
$size = $this->max_sftp_packet < $length || $length < 0 ? $this->max_sftp_packet : $length;
|
||||||
while (true) {
|
$read = 0;
|
||||||
$packet = pack('Na*N3', strlen($handle), $handle, $offset / 4294967296, $offset, $size);
|
$error = false;
|
||||||
|
while (!$error) {
|
||||||
|
$request_id_offset = 5;// just like that, a random number
|
||||||
|
$i = $request_id_offset;
|
||||||
|
|
||||||
|
// this puts a constraint on 32 bit systems where files larger than 4GB will not be completely downloaded if length is not specified.
|
||||||
|
$limit = $length > 0 ? max($this->max_sftp_packet, $length) : PHP_INT_MAX;
|
||||||
|
|
||||||
|
while ($i < NET_SFTP_QUEUE_SIZE+$request_id_offset && $read < $limit) {
|
||||||
|
$subtemp = $start + $read;
|
||||||
|
$possible_packet_sizes = array($this->max_sftp_packet, $size);
|
||||||
|
if ($limit - $read > 0) {
|
||||||
|
$possible_packet_sizes[] = $limit - $read;
|
||||||
|
}
|
||||||
|
|
||||||
|
$packet_size = min($possible_packet_sizes);
|
||||||
|
|
||||||
|
$packet = pack('Na*N3', strlen($handle), $handle, $subtemp / 4294967296, $subtemp, $packet_size);
|
||||||
|
$this->request_id = $i;
|
||||||
if (!$this->_send_sftp_packet(NET_SFTP_READ, $packet)) {
|
if (!$this->_send_sftp_packet(NET_SFTP_READ, $packet)) {
|
||||||
if ($fclose_check) {
|
if ($fclose_check) {
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$this->request_id=1;
|
||||||
|
|
||||||
|
$read += $packet_size;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($i > $request_id_offset) {
|
||||||
|
$this->request_id = $i;
|
||||||
$response = $this->_get_sftp_packet();
|
$response = $this->_get_sftp_packet();
|
||||||
|
$this->request_id=1;
|
||||||
switch ($this->packet_type) {
|
switch ($this->packet_type) {
|
||||||
case NET_SFTP_DATA:
|
case NET_SFTP_DATA:
|
||||||
$temp = substr($response, 4);
|
$temp = substr($response, 4);
|
||||||
@ -2087,7 +2113,9 @@ class SFTP extends SSH2
|
|||||||
case NET_SFTP_STATUS:
|
case NET_SFTP_STATUS:
|
||||||
// could, in theory, return false if !strlen($content) but we'll hold off for the time being
|
// could, in theory, return false if !strlen($content) but we'll hold off for the time being
|
||||||
$this->_logError($response);
|
$this->_logError($response);
|
||||||
break 2;
|
// don't break out of the loop so we can read the remaining responses
|
||||||
|
$error = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if ($fclose_check) {
|
if ($fclose_check) {
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
@ -2096,7 +2124,10 @@ class SFTP extends SSH2
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($length > 0 && $length <= $offset - $start) {
|
if ($length > 0 && $length <= $offset - $start) {
|
||||||
break;
|
// don't break out of the loop so we can read the remaining responses
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
$i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user