Here is my code:

    <?php
    $con = ssh2_connect('crm.idea.com.bd','4321');
    ssh2_auth_password($con, 'username', 'password');
    $response = ssh2_exec($con, 'pwd');
    echo $response;

?>

I can connect to that server using that username, password and port address. But when I load this script it don't work. It shows loading and loading continues. No error message is given.

N: B: Please help me. I am a newbie.

    Welcome to PHPBuilder!

    Can you show us the exact output from the above script? Also, can you do a [man]phpinfo/man and check to see if display_errors is set to On and error_reporting is set to E_ALL (or better)?

    Finally, note that you might want to incorporate some error checking into your code to verify that certain steps have succeeded. For example, [man]ssh2_connect/man returns boolean FALSE if an error occurs, thus the first thing you should do after calling that function is to see if $con is equal to FALSE before doing anything else with the connection. The same goes for [man]ssh2_auth_password/man as well.

      The page just loads and loads continuously as it will never end loading.

        6 months later

        Hey guys!
        The thread is a little old but it fits to my problem. I tried to connect to a remote server via ssh2_connect() but I don't receive any response. I know that connecting is possible because with the same parameters I get a connection using a shell.

        <?php
        
        class Login{
        
        private $connection;
        
        public function connect($server, $port, $login, $passwd){
        	if (!function_exists("ssh2_connect")){
        		return false;
        	}
        	if(!($this->connection = ssh2_connect($server, $port))){		    	
        		return false;
        	} 
        	else {	
        		if(!ssh2_auth_password($this->connection, $login, $passwd)) {
        			return false;
        		} 
        		else {
        			return true;
        	    	}
        	}
        }
        }
        
        $ssh = new Login();
        
        if($ssh->connect('some.sever.com', 22, 'username', 'somepasswd')){
        	echo "connected...";
        
        }
        else{
        	echo "no connection";
        }
        ?>

        display_errors is on and error_reporting is set to E_ALL. The page keeps loading and loading. Connect to other servers works fine...

        I check user data, firewalls, other servers and now I'm running out of ideas. Could somebody help me?

          First off, I'd use either [man]trigger_error[/man] or [man]error_log[/man] in the connect function to see which part of the code returns false. As it is, you have no information whatsoever on why the connection fails. [man]Is ssh2_connect[/man] missing? Does the attempt to connect fail? etc...

          Have you tried using ip instead of domain name?

            Heyho,

            after little reading in logs I found the problem: ssh2_connect() works fine but ssh2_auth_password() failed. The error was logged into apache's error log but somehow the function didn't return so the script was running in a deadlock. my build of libssh2 didn't support keyboard-interactive as mode for ssh2_auth_password()... Now I use public key authentification and it works.

              Write a Reply...