title: phpseclib: how to give IF condition to check connection established or not
body: <p>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.</p>
  
  <pre><code>&lt;?php
      include('Net/SSH2.php');
  
      define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
  
      $ssh = new Net_SSH2('10.3.2.0');
      if (!$ssh-&gt;login('makesubdomain','abcdabcd')) {
          exit('Login Failed');
      }
      echo $ssh-&gt;exec('/usr/local/listdomain.backup/test/makedir.sh');
  ?&gt;
  </code></pre>
  
  <p>Here my problem is, how can I give an <code>if</code> 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.</p>
  
  <pre><code>&lt;?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-&gt;login('abcd','abcdabcd')) {
               exit('Login Failed');
           }
           echo $ssh-&gt;exec('./test.sh');
      }
  ?&gt;
  </code></pre>
  
  <p>Please help me as I am very beginner in php. Thanks</p>