Question

This might be a simple question, but I haven't found anything so far and I'm not sure how to start.

I want to make several SSH connections in the same PHP file. I want them to be consecutive only if the last SSH connection succeeded.

The SSH connection script I'm using:

 $ssh = new Net_SSH2($ip);  if (!$ssh->login($sshuser, $sshpass)) { 
     exit('Login Failed'); }


 $ssh->exec($command1);



 $ssh = new Net_SSH2($ip2);  if (!$ssh->login($sshuser2, $sshpass2)) { 
     exit('Login Failed'); }


 $ssh->exec($command2);

There are 6 scripts in total. What do I need to do?

Was it helpful?

Solution

So basically you're wanting to do as many SSH connections as you can, until one fails, at which point, you won't do anymore? If that's the case it seems like your code will indeed work. If the first login() fails your script will exit..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top