unable to startup sftp subsystem

6.3k views Asked by At

I am trying to do a ssh connection in php. But I get this error Unable to startup sftp subsystem. I don't understand it. And I could not find much in google. Please let me know how to debug this. I am using wamp.

$resConnection = ssh2_connect($strServer, $strServerPort);

if(ssh2_auth_password($resConnection, $strServerUsername, $strServerPassword)){
    //Initialize SFTP subsystem
    $resSFTP = ssh2_sftp($resConnection); -->error coming here

}else{
    echo "Unable to authenticate on server";
}
2

There are 2 answers

0
Farid Movsumov On

I had the same issue and I solved it with following steps.

1) First I noticed that there is slowliness on server to which we are trying to make sftp connection.

2) There is a script in our side which try to connect and get files from server so because of slowliness issue our scripts can't complete their job and wait for connection because it was very slow. I checked how many processes created for sftp connection with following command

ps aux | grep sftp

3) Then I killed all these processes with following command

pkill sftp

4) After I kill that processes error was gone.

Summary

Main reason of this issue was that. There was slowliness issue in ftp server and we created too many connection. I think there is some limit on server side for max connections.

0
neubert On

It's hard to say without more information. Unfortunately, libssh2 is pretty limited in the amount of info it provides. I'd recommend you use phpseclib, a pure PHP SFTP implementation. eg.

<?php
include('Net/SFTP.php');

$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
    exit('Login Failed');
}

print_r($sftp->nlist());
?>

Put define('NET_SSH2_LOGGING', 3) at the top to get logs if you still encounter the problem, after switching. Then post the logs so that you can get better assistance.

Thanks!