title: phpseclib - can't connect to cisco switch
body: <p>I'm trying to use phpseclib to connect to a cisco SF308 switch. 
  I am using this library to successfully connect to some HP switches, but for some reason, it just won't work with my cisco.
  Here's the code: </p>
  
  <pre><code> set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/phpseclib');
   include('/var/www/phpseclib/Net/SSH2.php');
   define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX); //add near include lines
   $cisco = new Net_SSH2('10.10.10.10');
  
   if (!$cisco-&gt;login('username', 'password')) {
       exit('Login Failed');
   }
  
   echo $cisco-&gt;write('\n');
  
   echo $cisco-&gt;write('help');
   echo $cisco-&gt;read('/([0-9A-Z\-])*(#)(\s*)/i', NET_SSH2_READ_REGEX);  
   echo $cisco-&gt;data;
   echo $cisco-&gt;getLog();
   echo $cisco-&gt;disconnect();
  </code></pre>
  
  <p>It always dies with the Login Failed error message.  </p>
  
  <p>I've tried adding some debug statements in the NET_SSH2 library itself and its dying with the error number 51, which is defined as 'NET_SSH2_MSG_USERAUTH_FAILURE'.</p>
  
  <p>One thing that is different between the hp switches and this cisco is that when connecting manually, the hp is "smart" enough to pick up the username from the initial ssh command.  For example, if you were to do this at a command prompt: </p>
  
  <pre><code> ssh username@10.10.10.10
  </code></pre>
  
  <p>and then hit enter, it will pick up "username" as the username, and it will only prompt you for a password.
  With the cisco switch (SF302-08 is the model), it still prompts for both the username and the password.  Once i supply the username for a second time, and then the password, I can connect to the switch.</p>
  
  <p>I'm not sure if this is what's causing the problem, but it's something that is clearly different between the two switches.  I'm trying to find some documentation for the cisco to see if there's any way to change this / make it pick up the username in the initial connect request.  But if you have any other suggestions, please let me know!  I'm all ears.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>I turned on complex logging and got the full details of where it's failing, in case this helps. 
  Here's my latest code: </p>
  
  <pre><code> set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/phpseclib');
   include('Net/SSH2.php');
   define('NET_SSH2_LOGGING', true); //turn on logging.
  
   $ssh = new Net_SSH2('10.10.10.10'); //starting the ssh connection to localhost
   if (!$ssh-&gt;login('username', 'password')) { //if you can't log on...
      echo('Login Failed');
      echo 'Error message is: &lt;br&gt;';
      $log = $ssh-&gt;getLog(NET_SSH2_LOG_COMPLEX);
      foreach ($log as $logitem)  {
               echo $logitem.'&lt;br&gt;';
       }
  </code></pre>
  
  <p>This returns the following output: </p>
  
  <pre><code> Login FailedError message is:
   &lt;-
   -&gt;
   &lt;- NET_SSH2_MSG_KEXINIT (0.0118s)
   -&gt; NET_SSH2_MSG_KEXINIT (0s)
   -&gt; NET_SSH2_MSG_KEXDH_INIT (0s)
   &lt;- NET_SSH2_MSG_KEXDH_REPLY (0.7912s)
   -&gt; NET_SSH2_MSG_NEWKEYS (0s)
   &lt;- NET_SSH2_MSG_NEWKEYS (0s)
   -&gt; NET_SSH2_MSG_SERVICE_REQUEST (0s)
   &lt;- NET_SSH2_MSG_SERVICE_ACCEPT (0.4927s)
   -&gt; NET_SSH2_MSG_USERAUTH_REQUEST (0s)
   &lt;- NET_SSH2_MSG_USERAUTH_FAILURE (0.0059s)
  </code></pre>
  
  <p>So it is contacting the switch but as was mentioned in my initial post, it's failing while trying to authenticate the username/password.</p>