title: phpseclib connection closed by server?
body: <p>I have a pretty simple PHP script that tries to connect to SFTP server from a CENTOS 7 box. Using phpseclib via composer.</p>
  
  <pre><code>&lt;?php
  require('vendor/autoload.php');
  $usr = 'xx';
  $pwd = 'xx';
  $host = 'sftp.domain.com.au';
  
  $sftp = new SFTP($host);
  
  if($sftp-&gt;login($usr, $pwd)){
     echo "Connected.";
  }else {
     echo "Failed";
  }
  ?&gt;
  </code></pre>
  
  <p>And even used an RSA key</p>
  
  <pre><code>&lt;?php
  require('vendor/autoload.php');
  $usr = 'xx';
  $pwd = 'xx';
  $host = 'sftp.domain.com.au';
  
  $sftp = new SFTP($host);
  $rsa  = new RSA();
  $rsa-&gt;loadKey(file_get_contents("../../.ssh/id_rsa"));
  if($sftp-&gt;login($usr, $pwd, $rsa)){
     echo "Connected.";
  }else {
     echo "Failed";
  }
  ?&gt;
  </code></pre>
  
  <p>The script above with RSA actually did work a few times and got me connected. So I thought I need to understand why it works, and change a few things. I tried generating another key overwriting the existing key. But this time it didnt work anymore.</p>
  
  <p>I also turned on the NET_SFTP_LOGGING with no display error just a plain "Connection closed by server". I have been working on this for days.. </p>
  
  <p>Only thing I could think of is when I regenerated the key and overwrite the ID_RSA somehow maybe the server thinks its not the right key anymore?</p>
  
  <p>Also when I connect using WinSCP, it seems the FTP server is giving me an algorithm: ssh-rsa 4096 , sha256 and md5 code. Is this something I need to use in my PHP script to properly connect? Just trying to rule out any possibilities.</p>
  
  <p><strong>MORE DETAILS:</strong></p>
  
  <ul>
  <li>from work I can connect to the FTP server via FILEZILLA/WINSCP</li>
  <li>the CENTOS box server is part of our network at work.</li>
  <li>I cant connect to the FTP server from home.</li>
  <li>on the CENTOS box I enable configured the "ssh_config" and generated keys with ssh-kegen -t RSA , I even added the id_rsa.pub to authorized_keys</li>
  </ul>
  
  <p>Please anyone give us some advise as this is consuming me for DAYS hopefully not for weeks! Thanks in advance.</p>