我在我的項目中使用了phpseclib。我已經安裝了它並且正在使用以下類似於here示例的代碼進行測試。無法使用SSH2連接
更新的代碼:
1 require("Net/SSH2.php");
2
3 if (!class_exists('Net_SSH2')) die("Class Net_SSH2 doesn't exist!");
4
5 $ssh = new Net_SSH2('***'); // the host IP address
6
7 if (!method_exists($ssh, 'Net_SSH2')) die("Net_SSH2 class doesn't have Net_SSH2 method!");
8
9 if (!$ssh->login('***', '***')) { // (verified) username and password
10 echo "LOG: " . $ssh->getLog() . "<br>";
11 exit('Login failed!');
12 }
代碼更新2:
1 require("Net/SSH2.php");
2
3 define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
4
5 if (!class_exists('Net_SSH2')) die("Class Net_SSH2 doesn't exist!");
6
7 $ssh = new Net_SSH2('***'); // the host IP address
8
9 if (!method_exists($ssh, 'Net_SSH2')) die("Net_SSH2 class doesn't have Net_SSH2 method!");
10
11 if (!$ssh->login('***', '***')) { // (verified) username and password
12 echo "LOG: " . $ssh->getLog() . "<br>";
13 echo "ALL ERRORS: ";
14 print_r($ssh->getErrors());
15 echo "<br>LAST ERROR: " . $ssh->getLastError() . "<br>";
16 exit('Login failed!');
17 }
退出在行#16 getLog()
給什麼,所以很難知道問題出在哪裏。我使用PuTTY測試了登錄憑證。它也無法登錄到其他服務器。我無法理解什麼是造成這個問題。
任何幫助將不勝感激!
在第一行放上'define('NET_SSH2_LOGGING',2);'你就可以看到'$ ssh-> getLog()' – 2012-08-01 05:58:23
的輸出我試過了。它沒有顯示任何$ ssh-> getLog() – 2012-08-01 13:19:33