我想为自动化测试工具制作一个GUI,目前是在CLI中,我们需要将其转换为GUI,现在我面临的问题是我选择了HTML,CSS,JS作为前端,PHP作为前端后端,那么你们中的任何一个人都可以建议我如何登录到有IP的服务器吗?或者只是如何使用 PHP 代码登录 Linux 服务器?
最佳答案
您可以使用“Secure Shell2”PHP 模块通过 SSH 打开连接。
https://php.net/manual/en/book.ssh2.php
// open a SSH connection (hostname = IP or network name of the remote computer)
$connection = ssh2_connect('hostname', 22);
// authenticate by login / password
ssh2_auth_password($connection, 'username', 'password');
然后执行命令:
// execute a shell command on the remote computer (eg. 'php -v' to know the PHP version)
$stream = ssh2_exec($connection, 'php -v');
// read the result from the remote computer to your local computer
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
// print the result in your local computer
echo stream_get_contents($stream_out);
关于javascript - 如何使用PHP代码登录Linux服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29557196/