sam
sam

Reputation: 23

phpseclib Connection closed prematurely

I am trying to connect an SFTP server using phpseclib, but I get the following error

"Notice: Connection closed prematurely in \phpseclib\Net\SSH2.php on line 3396" and never get success message.

Login details are working fine on FileZilla.

Below is my code

use phpseclib\Crypt\RSA;
use phpseclib\Net\SSH2;

define('NET_SSH2_LOGGING', SSH2::LOG_COMPLEX);

$key = new RSA();
$key->setPassword('ppk file password');
$key->loadKey(file_get_contents('ppk file path'));

$ssh2 = new SSH2('domain:port');
if (!$ssh2->login('sftp user', $key)) {
    $log = $ssh2->getLog();
    echo $log;
    exit('Login Failed');
}else{
    exit('Success');
}

Any help why I am getting an error is much appreciated.

Upvotes: 2

Views: 5660

Answers (2)

neubert
neubert

Reputation: 16792

I had to go back to phpseclib 2.0.2 to find a version of phpseclib (2.0 branch) that had a user_error with "Connection closed prematurely" on line 3396:

https://github.com/phpseclib/phpseclib/blob/2.0.2/phpseclib/Net/SSH2.php#L3396

The latest version of phpseclib is 2.0.9. I'd try upgrading.

2.0.2 was released on June 4, 2016. 2.0.9 was released on Nov 29, 2017. A lot has changed in that time.

Upvotes: 0

Kareem Essawy
Kareem Essawy

Reputation: 615

In this case the SSH logs would probably be more helpful.

You can get them by doing define('NET_SSH2_LOGGING', 2) and then doing $ssh->getLog().

then you should take a look at the last few packets

can you also define what is your php version and what is the OS on the server ?

Upvotes: 1

Related Questions