I am having issues with the following code. This is just the pre-login section. The way this used to work was, I get the key from a file. create a new sftp object, set the preferred algorithm to ssh-dss (which is the only algorithm this particular server offers) and then login. And all was fine. I must have updated something on the server that botched things because the code didn't change but this bit is now broken.
I keep getting this error:
array_intersect(): Argument #1 ($array) must be of type array, string given
We're using PHP 8.0.30
PHPSECLIB 3.0
On Ubuntu 20.04.6
Apache 2.4.62
I've seen similar issues with WordPress but nothing that would give me a solution.
If you are able to help me solve this I would be very grateful.
$key = $this->__getKeyWithFile($mykey, $myphrase);
$sftp = new SFTP($host, $port);
if (!empty($sftp)) {
try {
$sftp->setPreferredAlgorithms(['hostkey' => 'ssh-dss']);
$sftp->login($user, $key)
} catch (Error $er) {
echo $er->getMessage();
} catch (Exception $ex) {
echo $ex->getMessage();
}
}
EDITED TO ADD full error. My bad. However the problem is solved below.
PHP Fatal error: Uncaught TypeError: array_intersect(): Argument #1 ($array) must be of type array, string given in /vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:4623
Stack trace:
#0 /vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php(4623): array_intersect()
#1 FTPTools.php(105): phpseclib3\Net\SSH2->setPreferredAlgorithms()
#2 Reporter.php(1247): FTPTools->login()
#3 run_rebot.php(60): Reporter->myfunction()
#4 {main}
thrown in /vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php on line 4623
I tried updating my server. I tried re-installing phpseclib. Neither worked.
You're doing this:
$sftp->setPreferredAlgorithms(['hostkey' => 'ssh-dss']);
When you should be doing this:
$sftp->setPreferredAlgorithms(['hostkey' => ['ssh-dss']]);