diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 0c0bac49..b50adf99 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -349,8 +349,6 @@ class SFTP extends SSH2 */ private function partial_init_sftp_connection(): bool { - $this->window_size_server_to_client[self::CHANNEL] = $this->window_size; - $response = $this->openChannel(self::CHANNEL, true); if ($response === true && $this->isTimeout()) { return false; diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 4d73bd7d..ff374ccb 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2754,6 +2754,10 @@ class SSH2 */ public function read(string $expect = '', int $mode = self::READ_SIMPLE, int $channel = null) { + if (!$this->isAuthenticated()) { + throw new InsufficientSetupException('Operation disallowed prior to login()'); + } + $this->curTimeout = $this->timeout; $this->is_timeout = false; @@ -2761,7 +2765,7 @@ class SSH2 $channel = $this->get_interactive_channel(); } - if (!$this->isInteractiveChannelOpen($channel) && empty($this->channel_buffers[$channel])) { + if (!$this->is_channel_status_data($channel) && empty($this->channel_buffers[$channel])) { if ($channel != self::CHANNEL_SHELL) { throw new InsufficientSetupException('Data is not available on channel'); } elseif (!$this->openShell()) { @@ -2809,11 +2813,15 @@ class SSH2 */ public function write(string $cmd, int $channel = null): void { + if (!$this->isAuthenticated()) { + throw new InsufficientSetupException('Operation disallowed prior to login()'); + } + if ($channel === null) { $channel = $this->get_interactive_channel(); } - if (!$this->isInteractiveChannelOpen($channel)) { + if (!$this->is_channel_status_data($channel)) { if ($channel != self::CHANNEL_SHELL) { throw new InsufficientSetupException('Data is not available on channel'); } elseif (!$this->openShell()) {