|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-12-03 14:17 UTC] shiv dot modi4 at gmail dot com
Description:
------------
I am trying connect another remote server using ssh. PHP provides a number of functions to do that. When i try to connect server2(assume) using ssh2_connect function from my local system wamp server it works. But when i try the same from my server1 to connect to server2 then it's not working. Everything is installed on server1 -- openssh, libssh2 etc. I have also done with changes with php.ini file by adding extension php_ssh2.so. Folowing is the script i am using. It's showing the any error.
unable to establish connection
But when i checked the apache error log file. it shows the following
[Sat Dec 03 19:30:35 2011] [error] [client 172.16.xxx.xx] PHP Warning: ssh2_connect(): Unable to connect to 172.18.xx.xxx on port 22 in /var/www/html/connection.php on line 9
[Sat Dec 03 19:30:35 2011] [error] [client 172.16.xxx.xx] PHP Warning: ssh2_connect(): Unable to connect to 172.18.xx.xxx in /var/www/html/connection.php on line 9
I am trying to find the problem from last few days. Please help!!!!!
Test script:
---------------
if (!function_exists("ssh2_connect"))
die("function ssh2_connect doesn't exist");
if(!($con = ssh2_connect("172.18.xx.xxx", 22))){
echo "fail: unable to establish connection\n";
} else {
if(!ssh2_auth_password($con, "admin", "admin")) {
echo "fail: unable to authenticate\n";
} else {
echo "okay: root logged in...\n";
echo ssh2_exec($con, "dir");
}
}
Expected result:
----------------
okay: root logged in... and list of directories
Actual result:
--------------
fail: unable to establish connection
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
I always use the below before attempting to execute a connection via ssh2_connect/etc. try{ $fp = fsockopen($host, 22, $errno, $errstr, 5); if(!$fp){ throw new Exception('Port 22 Is Obstructed - '.$errstr); return false; } fclose($fp); }catch(Exception $e){ die($e->getMessage()); } What are your results?