Skip to content

Commit

Permalink
Revert "SFTP: don't buffer up download requests (PuTTY doesn't)"
Browse files Browse the repository at this point in the history
This reverts commit 333e2e4.
  • Loading branch information
terrafrost committed Feb 25, 2020
1 parent 6cb500d commit db6ce98
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions phpseclib/Net/SFTP.php
Expand Up @@ -1701,6 +1701,13 @@ function _setstat_recursive($path, $attr, &$i)
}

$i++;

if ($i >= NET_SFTP_QUEUE_SIZE) {
if (!$this->_read_put_responses($i)) {
return false;
}
$i = 0;
}
}
}

Expand All @@ -1710,8 +1717,11 @@ function _setstat_recursive($path, $attr, &$i)

$i++;

if (!$this->_read_put_responses($i)) {
return false;
if ($i >= NET_SFTP_QUEUE_SIZE) {
if (!$this->_read_put_responses($i)) {
return false;
}
$i = 0;
}

return true;
Expand Down Expand Up @@ -2081,7 +2091,7 @@ function put($remote_file, $data, $mode = NET_SFTP_STRING, $start = -1, $local_s

$subtemp = $offset + $sent;
$packet = pack('Na*N3a*', strlen($handle), $handle, $subtemp / 4294967296, $subtemp, strlen($temp), $temp);
if (!$this->_send_sftp_packet(NET_SFTP_WRITE, $packet, $i)) {
if (!$this->_send_sftp_packet(NET_SFTP_WRITE, $packet)) {
if ($mode & NET_SFTP_LOCAL_FILE) {
fclose($fp);
}
Expand All @@ -2093,6 +2103,14 @@ function put($remote_file, $data, $mode = NET_SFTP_STRING, $start = -1, $local_s
}

$i++;

if ($i == NET_SFTP_QUEUE_SIZE) {
if (!$this->_read_put_responses($i)) {
$i = 0;
break;
}
$i = 0;
}
}

if (!$this->_read_put_responses($i)) {
Expand Down Expand Up @@ -2380,8 +2398,10 @@ function delete($path, $recursive = true)
if (!$recursive) {
return false;
}

return $this->_delete_recursive($path);
$i = 0;
$result = $this->_delete_recursive($path, $i);
$this->_read_put_responses($i);
return $result;
}

$this->_remove_from_stat_cache($path);
Expand All @@ -2399,8 +2419,11 @@ function delete($path, $recursive = true)
* @return bool
* @access private
*/
function _delete_recursive($path)
function _delete_recursive($path, &$i)
{
if (!$this->_read_put_responses($i)) {
return false;
}
$i = 0;
$entries = $this->_list($path, true);

Expand Down Expand Up @@ -2428,6 +2451,13 @@ function _delete_recursive($path)
$this->_remove_from_stat_cache($temp);

$i++;

if ($i >= NET_SFTP_QUEUE_SIZE) {
if (!$this->_read_put_responses($i)) {
return false;
}
$i = 0;
}
}
}

Expand All @@ -2438,8 +2468,11 @@ function _delete_recursive($path)

$i++;

if (!$this->_read_put_responses($i)) {
return false;
if ($i >= NET_SFTP_QUEUE_SIZE) {
if (!$this->_read_put_responses($i)) {
return false;
}
$i = 0;
}

return true;
Expand Down

1 comment on commit db6ce98

@terrafrost
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1455

Please sign in to comment.