|
 |
|
สอบถามเรื่องการใช้งาน function ssh2_connect มีปัญหาการเรียกใช้งานผ่าน Web Browser |
|
 |
|
|
 |
 |
|
มี error บนหน้าจอหรือใน log file มั้ยครับ?
|
 |
 |
 |
 |
Date :
2013-04-21 20:04:08 |
By :
itpcc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
echo "Start Connection..\n";
if(!$con = ssh2_connect('127.0.0.1', 22))
{
echo "fail: unable to establish connections\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, 'root', 'password')) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";
// execute a command
if (!($stream = ssh2_exec($con, 'ls'))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
echo $data;
}
}
}
?>
ถ้าเรียกผ่าน Terminal โดยใช้คำสั่ง php /var/www/html/ssh.php จะสามารถแสดงผล ของการใช้คำสั่ง 'ls' ได้อย่างถูกต้อง
แต่ว่าถ้าเรียกผ่าน webbrowser http://localhost/ssh.php จะขึ้นข้อความ error ในขั้นตอนของการทำ connection ('fail: unable to establish connections') ครับ
|
ประวัติการแก้ไข 2013-04-21 23:00:22
 |
 |
 |
 |
Date :
2013-04-21 22:55:54 |
By :
itchaz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|