0

I am using PHPSeclib to access server with dokku-alt installed:

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. According to Net_SSH2 documentation, I need to write the data into SSH stream instead of using 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? 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.

4

1 回答 1

0

我认为 PTY 模式是您正在寻找的?例如。

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

更多信息:

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

于 2014-09-21T16:14:31.017 回答