I have PHP script which uses ssh utility to connect to a remote Ubuntu machine for executing some commands there. The script is as given below.
<?php
include('Net/SSH2.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
$ssh = new Net_SSH2('10.3.2.0');
if (!$ssh->login('makesubdomain','abcdabcd')) {
exit('Login Failed');
}
echo $ssh->exec('/usr/local/listdomain.backup/test/makedir.sh');
?>
Here my problem is, how can I give an if
condition to check whether the connection failed or not. I am trying to modify the above code something like this, but I know this is very wrong.
<?php
include('Net/SSH2.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
if(!$ssh = new Net_SSH2('10.3.2.0')) // Here how can I give condtion
{
echo "Connection failed";
}else{
if (!$ssh->login('abcd','abcdabcd')) {
exit('Login Failed');
}
echo $ssh->exec('./test.sh');
}
?>
Please help me as I am very beginner in php. Thanks