get output from ssh2_shell

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kenqcl@gmail.com

    get output from ssh2_shell

    Hi,
    I try to use SSH2 in PHP to connect to a linux server. Here is the
    code:
    <pre>
    $connection = ssh2_connect('x xx', 22);
    if( !$connection ) die("Failed to connect");

    if( ! ssh2_auth_passw ord($connection , 'aaa', 'bbb') )
    die("FAIL");

    $s = ssh2_shell($con nection, "vt100");
    if( !$s ) die("Can not attach stdio.");

    fwrite($s, "ls /tmp");

    $o = fread($s, 100);
    echo $o;
    </pre>

    But I can't get any output using fread. How can I get the
    output(STDOUT)?
    Any help is appreciated! Thanks in advance.
    Have a nice day!

    Regards
    KEN

  • Daniel Tryba

    #2
    Re: get output from ssh2_shell

    kenqcl@gmail.co m wrote:[color=blue]
    > fwrite($s, "ls /tmp");
    >
    > $o = fread($s, 100);[/color]
    [color=blue]
    > But I can't get any output using fread. How can I get the
    > output(STDOUT)?[/color]

    That's because you didn't tell the shell to do somehting, you only send
    some characters... Try appending "\n" to tell the shell to execute
    received chars.

    Comment

    Working...