1

I'm using php ssh2 lib to execute command on server, command code as below:

RSC_delete ABCD
Are you sure to delete RSC data [N] ('Y' or 'N')  Y

As you can see it require a 'Y' key for it to execute delete.

My PHP code is as follow:

        $connection = ssh2_connect($ip,22);
        ssh2_auth_password($connection, $ftp_act,"")

        $cmd="RSC_delete ABCD";
        $cmd2='Y';

        $stream = ssh2_exec($connection, $cmd);
        $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
        stream_set_blocking($errorStream, true);
        stream_set_blocking($stream, true);
        $m1 = str_replace("\n","<br>",stream_get_contents($stream));
        fclose($errorStream);
        fclose($stream);

        $stream = ssh2_exec($connection, $cmd2);
        $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
        stream_set_blocking($errorStream, true);
        stream_set_blocking($stream, true);
        $m1 = str_replace("\n","<br>",stream_get_contents($stream));
        fclose($errorStream);
        fclose($stream);
CodingNuts
  • 19
  • 1
  • 6

0 Answers0