tweak version management stuff

This commit is contained in:
terrafrost 2021-08-29 13:11:26 -05:00
parent 42b4ab065b
commit 41b5f7cfe9

View File

@ -196,6 +196,15 @@ class Net_SFTP extends Net_SSH2
*/ */
var $version; var $version;
/**
* Default Server SFTP version
*
* @var int
* @see self::_initChannel()
* @access private
*/
var $defaultVersion;
/** /**
* Current working directory * Current working directory
* *
@ -609,7 +618,7 @@ class Net_SFTP extends Net_SSH2
return false; return false;
} }
extract(unpack('Nversion', $this->_string_shift($response, 4))); extract(unpack('Nversion', $this->_string_shift($response, 4)));
$this->version = $version; $this->defaultVersion = $version;
while (!empty($response)) { while (!empty($response)) {
if (strlen($response) < 4) { if (strlen($response) < 4) {
return false; return false;
@ -664,11 +673,12 @@ class Net_SFTP extends Net_SSH2
in draft-ietf-secsh-filexfer-13 would be quite impossible. As such, what Net_SFTP would do is close the in draft-ietf-secsh-filexfer-13 would be quite impossible. As such, what Net_SFTP would do is close the
channel and reopen it with a new and updated SSH_FXP_INIT packet. channel and reopen it with a new and updated SSH_FXP_INIT packet.
*/ */
$this->version = $this->defaultVersion;
if (isset($this->extensions['versions']) && (!$this->preferredVersion || $this->preferredVersion != $this->version)) { if (isset($this->extensions['versions']) && (!$this->preferredVersion || $this->preferredVersion != $this->version)) {
$versions = explode(',', $this->extensions['versions']); $versions = explode(',', $this->extensions['versions']);
$supported = array(6, 5, 4); $supported = array(6, 5, 4);
if ($this->preferredVersion) { if ($this->preferredVersion) {
$supported = array_diff($supported, [$this->preferredVersion]); $supported = array_diff($supported, array($this->preferredVersion));
array_unshift($supported, $this->preferredVersion); array_unshift($supported, $this->preferredVersion);
} }
foreach ($supported as $ver) { foreach ($supported as $ver) {
@ -3624,13 +3634,28 @@ SFTP v6 changes (from v5)
$this->_partial_init_sftp_connection(); $this->_partial_init_sftp_connection();
} }
$temp = array('version' => $this->version); $temp = array('version' => $this->defaultVersion);
if (isset($this->extensions['versions'])) { if (isset($this->extensions['versions'])) {
$temp['extensions'] = $this->extensions['versions']; $temp['extensions'] = $this->extensions['versions'];
} }
return $temp; return $temp;
} }
/**
* Get supported SFTP versions
*
* @return array
* @access public
*/
function getNegotiatedVersion()
{
if (!$this->_precheck()) {
return false;
}
return $this->version;
}
/** /**
* Set preferred version * Set preferred version
* *