|
|
|
อยากเขียนโปรแกรม SSH Client ติดต่อกับ OpenSSH-Server บน Linux Server ด้วย PHP รบกวนช่วยแนะนำด้วยครับ |
|
|
|
|
|
|
|
ลองใช้ดูครับอันนี้ผมใช้อยู่
Code (PHP)
$callbacks = array('disconnect' => 'my_ssh_disconnect');
$username = $SCONFIG['username'];
$password = $SCONFIG['password'];
$remotepath = $SCONFIG['remotepath'];
$localpath = $SCONFIG['localpath'];
$methods = array(
'kex' => 'diffie-hellman-group1-sha1',
'client_to_server' => array(
'crypt' => '3des-cbc',
'comp' => 'none'),
'server_to_client' => array(
'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc',
'comp' => 'none')
);
//$connection = ssh2_connect($host, 22);
$connection = ssh2_connect($host, 22, $methods, $callbacks);
ssh2_auth_password($connection, $username, $password);
if (!$connection)
{
echo "Connection Failed<br>\n";
exit();
}
$sftp = ssh2_sftp($connection);
$handledir = "ssh2.sftp://".$sftp.$remotepath;
$com ="ls $remotepath";
$stream = ssh2_exec($connection, $com);
stream_set_blocking($stream,true);
/*********
*
* ชุดคำสั่งที่ต้องการ
/**********/
closeconnect($connection);
/*******************************/
function closeconnect($connect)
{
ssh2_exec($connect, 'exit');
return;
}
function my_ssh_disconnect($reason, $message, $language) {
printf("Server disconnected with reason code [%d] and message: %s\n",
$reason, $message);
}
exit();
|
|
|
|
|
Date :
2013-07-16 17:05:22 |
By :
mulline |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|