看看this ssh2模块在PHP中,文档是here。
这是你如何连接并执行你的命令:
<?php
/* Notify the user if the server terminates the connection */
function my_ssh_disconnect($reason, $message, $language) {
printf("Server disconnected with reason code [%d] and message: %s\n",
$reason, $message);
}
public function my_exec_cmd($connection, $cmd) {
if (!($stream = ssh2_exec($connection, $cmd))) {
throw new Exception('SSH command failed');
}
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream, 4096)) {
$data .= $buf;
}
fclose($stream);
return $data;
}
$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'));
$callbacks = array('disconnect' => 'my_ssh_disconnect');
$connection = ssh2_connect('shell.example.com', 22, $methods, $callbacks);
if (!$connection){
die('Connection failed');
}else{
my_exec_cmd($connection, "ls -la");
}
?>
我正在解决方案:)。希望我能尽快完成。 – robert
为什么不把你的快捷方式作为别名写在.bashrc中? –
我在编写我的所有任务时都保持一致,因此所有开发人员都可以轻松完成任务。我希望能够运行“./dep ssh stage”,“./dep release stage”,“。/ del日志阶段“交互ssh登台服务器,释放和查看日志分别('释放'任务是一个非交互式的一组SSH任务) – fstr