So just look at the output of this code, it really will help you to debug
<?php
$password = "Password";
$commandOne = 'sshpass -p "'.$password.'" scp -o StrictHostKeyChecking=no /file.txt [email protected]:/home/user/ 2>&1';
$commandTwo = 'sshpass -p "Password" scp -o StrictHostKeyChecking=no /file.txt [email protected]:/home/user/ 2>&1';
echo $commandOne . PHP_EOL;
echo $commandTwo . PHP_EOL;
output
sshpass -p "Password" scp -o StrictHostKeyChecking=no /file.txt [email protected]:/home/user/ 2>&1
sshpass -p "Password" scp -o StrictHostKeyChecking=no /file.txt [email protected]:/home/user/ 2>&1
They are completly same when I use put "Pasword" in the password variable, so now just try to put your real pass and compare them, it will show you the problem
If you get the same result just try this in your code
<?php
$password = "Password";
$command = 'sshpass -p "'.$password.'" scp -o StrictHostKeyChecking=no /file.txt [email protected]:/home/user/ 2>&1';
shell_exec($command);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…