connection) { $this->connection->disconnect(); } } public function provideConnection(): SFTP { if ( ! $this->connection instanceof SFTP || ! $this->connection->isConnected()) { $connection = new SftpStub($this->host, $this->port); $connection->login($this->username, $this->password); $this->connection = $connection; } return $this->connection; } }