简体   繁体   English

将phpseclib与自定义外壳程序一起使用

[英]Using phpseclib with a custom shell wrapper

I am using PHPSeclib to access server with dokku-alt installed: 我正在使用PHPSeclib访问安装了dokku-alt的服务器:

http://dokku-alt.github.io/how-it-works.html http://dokku-alt.github.io/how-it-works.html

By following a typical example, I manage to send commands to a custom shell on my account: 通过遵循一个典型示例,我设法将命令发送到我帐户上的自定义外壳程序:

    $ssh=$this->connect();
    echo trim($ssh->exec("version");

This is equivalent to 这相当于

ssh dokku@my.node.org version

and works as expected. 并按预期工作。 If I however try to execute a command which expects me to send data through STDIN, there is a problem. 但是,如果我尝试执行一个期望我通过STDIN发送数据的命令,则会出现问题。 According to Net_SSH2 documentation, I need to write the data into SSH stream instead of using exec(). 据Net_SSH2文件,我需要write数据到SSH流,而不是使用EXEC()。 Unfortunately my next example does not work, because custom shell does not receive any argument and responds with help page: 不幸的是,我的下一个示例不起作用,因为自定义外壳程序不接收任何参数,并以帮助页面作为响应:

    $ssh=$this->connect();
    $ssh->write("mysql mariadb:console myapp newdb\n");
    $ssh->write("show tables\n");
    $ssh->read('[prompt]');

The result of this is identical to 其结果与

ssh dokku@my.node.org

which simply responds with help page. 它只是以帮助页面作为响应。

How can I combine the "exec" functionality and still be able to write data? 如何结合“ exec”功能并且仍然能够写入数据? Something like this does not work either: 这样的事情也不起作用:

    $ssh=$this->connect();
    $ssh->exec("mysql mariadb:console myapp newdb");
    $ssh->write("show tables\n");
    $ssh->read('[prompt]');

Thank you. 谢谢。

I think PTY mode is what you're looking for? 我认为您正在寻找PTY模式? eg. 例如。

$ssh->enablePTY(); 
$ssh->exec('mysql mariadb:console myapp newdb'); 
echo $ssh->read('mysql>'); 
$ssh->write("show tables\n");
echo $ssh->read('mysql>');

More info: 更多信息:

http://phpseclib.sourceforge.net/ssh/pty.html http://phpseclib.sourceforge.net/ssh/pty.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM