当前位置: 首页>>代码示例>>PHP>>正文


PHP ssh2_fetch_stream函数代码示例

本文整理汇总了PHP中ssh2_fetch_stream函数的典型用法代码示例。如果您正苦于以下问题:PHP ssh2_fetch_stream函数的具体用法?PHP ssh2_fetch_stream怎么用?PHP ssh2_fetch_stream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ssh2_fetch_stream函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sshiconn

function sshiconn($cmd, $pass, $ip, $sshp = 22)
{
    $ip = $_REQUEST['ip'];
    $pass = $_REQUEST['pass'];
    $sshp = $_REQUEST['sshp'];
    if (!isset($_REQUEST['sshp'])) {
        $sshp = '22';
    }
    $connection = ssh2_connect($ip, $sshp);
    if (!$connection) {
        throw new Exception("fail: unable to establish connection\nPlease IP or if server is on and connected");
    }
    $pass_success = ssh2_auth_password($connection, 'root', $pass);
    if (!$pass_success) {
        throw new Exception("fail: unable to establish connection\nPlease Check your password");
    }
    $stream = ssh2_exec($connection, $cmd);
    $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
    stream_set_blocking($errorStream, true);
    stream_set_blocking($stream, true);
    print_r($cmd);
    $output = stream_get_contents($stream);
    fclose($stream);
    fclose($errorStream);
    ssh2_exec($connection, 'exit');
    unset($connection);
    return $output;
}
开发者ID:shadowhome,项目名称:synxb,代码行数:28,代码来源:functions.php

示例2: exec

 /**
  * @param $command
  * @param bool $display
  * @return array
  * @throws \Exception
  */
 public function exec($command, $display = true)
 {
     $outStream = ssh2_exec($this->stream, $command);
     $errStream = ssh2_fetch_stream($outStream, SSH2_STREAM_STDERR);
     stream_set_blocking($outStream, true);
     stream_set_blocking($errStream, true);
     $err = $this->removeEmptyLines(explode("\n", stream_get_contents($errStream)));
     if (count($err)) {
         if (strpos($err[0], 'Cloning into') === false) {
             // throw new \Exception(implode("\n", $err));
         }
     }
     $out = $this->removeEmptyLines(explode("\n", stream_get_contents($outStream)));
     fclose($outStream);
     fclose($errStream);
     if ($display) {
         if (!$this->output instanceof OutputInterface) {
             throw new \LogicException('You should set output first');
         }
         foreach ($out as $line) {
             $this->output->writeln(sprintf('<info>%s</info>', $line));
         }
     }
     return $out;
 }
开发者ID:seferov,项目名称:deployer-bundle,代码行数:31,代码来源:SshClient.php

示例3: handle

 public function handle()
 {
     /**
      * Estamblish SSH connection,
      * put site under maintenance,
      * pull chamges from git,
      * install composer dependencies,
      * execute migrations,
      * put site online
      */
     $remote = config('pckg.framework.' . DeployProject::class . '.remotes.default');
     $path = $remote['root'];
     $commands = ['cd ' . $path => 'Changing root directory', 'php ' . $path . 'console project:down' => 'Putting project offline', 'php ' . $path . 'console project:pull' => 'Executing project:pull', 'php ' . $path . 'console migrator:install' => 'Installing migrations', 'php ' . $path . 'console project:up' => 'Putting project up', 'php ' . $path . 'console cache:clear' => 'Clearing cache'];
     $this->output('Estamblishing SSH connection.');
     $sshConnection = ssh2_connect($remote['host'], $remote['port']);
     $this->output('SSH connection estamblished.');
     /**
      * Authenticate.
      */
     if (!ssh2_auth_password($sshConnection, $remote['username'], $remote['password'])) {
         throw new Exception('Cannot estamblish SSH connection to remote');
     }
     foreach ($commands as $command => $notice) {
         $this->output($notice);
         $stream = ssh2_exec($sshConnection, $command);
         $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
         stream_set_blocking($errorStream, true);
         stream_set_blocking($stream, true);
         $errorStreamContent = stream_get_contents($errorStream);
         $streamContent = stream_get_contents($stream);
         $this->output($errorStreamContent . "\n" . $streamContent);
     }
     $this->output('Done!');
 }
开发者ID:pckg,项目名称:framework,代码行数:34,代码来源:DeployProject.php

示例4: getOS

function getOS($pass = false)
{
    $ip = $_REQUEST['ip'];
    $lsbresult1 = array();
    if (isset($pass) && $pass) {
        $connection = ssh2_connect($ip, 22);
        echo ssh2_auth_password($connection, 'root', $pass) ? 'success' : 'fail';
        $cmd = "lsb_release -as";
        $stream = ssh2_exec($connection, $cmd);
        $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
        stream_set_blocking($errorStream, true);
        stream_set_blocking($stream, true);
        $lsbresult1 = stream_get_contents($stream);
    } else {
        $lsbresult1 = array();
        exec("ssh sysad@{$ip} 'lsb_release -as'", $lsbresult1);
    }
    $lsbresult = explode("\n", $lsbresult1);
    if (!empty($lsbresult)) {
        $OS = $lsbresult[0];
        $version = $lsbresult[3];
        $releasever = $lsbresult[2];
    } else {
        echo "No values present";
        die;
    }
    return array($OS, $version, $releasever);
}
开发者ID:blaizeliebs,项目名称:synx,代码行数:28,代码来源:functions.php

示例5: getSegmentedOutput

 /**
  * Get the complete output from the command, separating stdout and stderr
  *
  * Returns an associative array:
  * ['stdout' => string, 'stderr' => string]
  *
  * @return string[]
  */
 public function getSegmentedOutput()
 {
     $this->close();
     $stderr = ssh2_fetch_stream($this->resource, SSH2_STREAM_STDERR);
     stream_set_blocking($this->resource, true);
     stream_set_blocking($stderr, true);
     $out = stream_get_contents($this->resource);
     $err = stream_get_contents($stderr);
     return ['stdout' => $out, 'stderr' => $err];
 }
开发者ID:bravo3,项目名称:ssh,代码行数:18,代码来源:ExecutionStream.php

示例6: _bubbleSshErrors

 protected function _bubbleSshErrors($sshStream, $commandString)
 {
     $errorStream = ssh2_fetch_stream($sshStream, SSH2_STREAM_STDERR);
     stream_set_blocking($errorStream, true);
     $error = stream_get_contents($errorStream);
     fclose($errorStream);
     if ($error) {
         $error = 'While executing [' . $commandString . '] ' . $error;
         throw new Exception($error);
     }
 }
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:11,代码来源:Abstract.php

示例7: run

 public function run($cmd, $pty = false, $env = null, $width = 80, $height = 25, $width_height_type = SSH2_TERM_UNIT_CHARS)
 {
     $stdout = ssh2_exec($this->getResource(), $cmd, $pty, $env, $width, $height, $width_height_type);
     $stderr = ssh2_fetch_stream($stdout, SSH2_STREAM_STDERR);
     stream_set_blocking($stderr, true);
     stream_set_blocking($stdout, true);
     $error = stream_get_contents($stderr);
     if ($error !== '') {
         throw new RuntimeException($error);
     }
     return stream_get_contents($stdout);
 }
开发者ID:mikemeier,项目名称:php-ssh,代码行数:12,代码来源:Exec.php

示例8: executeCommand

 private function executeCommand($command)
 {
     echo "\nrunning command....." . $command . PHP_EOL;
     $stream = ssh2_exec($this->connection, $command);
     echo "\ntimeout is....." . $this->timeout . PHP_EOL;
     $connectionTimeout = time();
     $connectionTimeout = $connectionTimeout + (int) $this->timeout * 60;
     stream_set_blocking($stream, false);
     $error_stream = "";
     $result = 0;
     $finalresult = 1;
     $errMessage = "";
     sleep(30);
     $err_stream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
     while (time() < $connectionTimeout) {
         sleep(1);
         if ($err = fgets($err_stream)) {
             //flush();
             echo $err;
             $errMessage .= $err;
             $err = "";
             $connectionTimeout = time();
             $connectionTimeout = $connectionTimeout + (int) $this->timeout * 60;
         }
         if ($cmd = fgets($stream)) {
             //flush();
             echo $cmd . PHP_EOL;
             if (strstr($cmd, "EXECCOMPLETED=") == true) {
                 if (strstr($cmd, "EXECCOMPLETED=0") == false && strstr($cmd, "EXECCOMPLETED=%ERRORLEVEL%") == false) {
                     $result = 1;
                 }
                 if (strstr($cmd, "EXECCOMPLETED=0") == true) {
                     $finalresult = 0;
                 }
                 break;
             }
             $connectionTimeout = time();
             $connectionTimeout = $connectionTimeout + (int) $this->timeout * 60;
         }
         $connectionTimeout = time();
         $connectionTimeout = $connectionTimeout + (int) $this->timeout * 60;
         //else {
         //		break;
         //	}
     }
     if (empty($errMessage) == false && $finalresult != 0) {
         echo "\nUnable to  execute" . $errMessage . PHP_EOL;
         $result = 1;
     }
     fclose($err_stream);
     fclose($stream);
     return $result;
 }
开发者ID:syamk,项目名称:CloudMunch-php-SDK-V1,代码行数:53,代码来源:RemoteExecutor.php

示例9: exec

 /**
  * @param $cmd
  * @param bool $pty
  * @param null $env
  * @return string
  * @throws RemoteShellCommandException
  */
 public function exec($cmd, $pty = FALSE, $env = NULL)
 {
     $result = ssh2_exec($this->connection->getConnection(), $cmd, $pty, $env);
     $errorStream = ssh2_fetch_stream($result, SSH2_STREAM_STDERR);
     stream_set_blocking($errorStream, TRUE);
     stream_set_blocking($result, TRUE);
     $error = stream_get_contents($errorStream);
     if (!empty($error)) {
         throw new RemoteShellCommandException($error);
     }
     return stream_get_contents($result);
 }
开发者ID:brabijan,项目名称:ssh,代码行数:19,代码来源:RemoteShell.php

示例10: __construct

 /**
  * Construct an execution stream in blocking mode.
  *
  * @param resource $stream
  *
  * @throws UnexpectedValueException if $stream is not a valid stream
  */
 public function __construct($stream)
 {
     if (!Valid::streamResource($stream)) {
         throw new UnexpectedValueException('Parameter must be a valid stream resource');
     }
     $stderr = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
     if (!$stderr) {
         throw new UnexpectedValueException('Parameter is a valid stream, but does not contain an »stderr« substream');
     }
     $this->stdio = $stream;
     $this->stderr = $stderr;
 }
开发者ID:moccalotto,项目名称:ssh,代码行数:19,代码来源:ExecutionStream.php

示例11: run

 public function run($cmd, $pty = null, array $env = array(), $width = 80, $height = 25, $width_height_type = SSH2_TERM_UNIT_CHARS)
 {
     $cmd .= ';echo -ne "[return_code:$?]"';
     $stdout = ssh2_exec($this->getResource(), $cmd, $pty, $env, $width, $height, $width_height_type);
     $stderr = ssh2_fetch_stream($stdout, SSH2_STREAM_STDERR);
     stream_set_blocking($stderr, true);
     stream_set_blocking($stdout, true);
     $output = stream_get_contents($stdout);
     preg_match('/\\[return_code:(.*?)\\]/', $output, $match);
     if ((int) $match[1] !== 0) {
         throw new RuntimeException(stream_get_contents($stderr), (int) $match[1]);
     }
     return preg_replace('/\\[return_code:(.*?)\\]/', '', $output);
 }
开发者ID:jimigrunge,项目名称:php-ssh,代码行数:14,代码来源:Exec.php

示例12: execute

 /**
  * Execute a SSH command
  *
  * @param string $cmd The SSH command
  *
  * @return string The output
  */
 public function execute($cmd)
 {
     // if ( false === $stream = ssh2_exec( $this->connection, $cmd ) ) {
     //     throw new SshException( sprintf( '"%s" : SSH command failed', $cmd ) );
     // }
     $stdout = ssh2_exec($this->connection, $cmd);
     $stderr = ssh2_fetch_stream($stdout, SSH2_STREAM_STDERR);
     stream_set_blocking($stderr, true);
     stream_set_blocking($stdout, true);
     $error = stream_get_contents($stderr);
     if ($error !== '') {
         throw new \RuntimeException($error);
     }
     return stream_get_contents($stdout);
 }
开发者ID:fiunchinho,项目名称:plumber,代码行数:22,代码来源:SshConnection.php

示例13: ssh_command

function ssh_command($command, $blocking)
{
    global $connection;
    $reply = ssh2_exec($connection, $command);
    $errorReply = ssh2_fetch_stream($reply, SSH2_STREAM_STDERR);
    stream_set_blocking($reply, $blocking);
    stream_set_blocking($errorReply, $blocking);
    $output = stream_get_contents($reply);
    $error = stream_get_contents($errorReply);
    if (!empty($output)) {
        return $output;
    } else {
        return $error;
    }
}
开发者ID:BillTheBest,项目名称:kvm-vdi,代码行数:15,代码来源:functions.php

示例14: exec

 public function exec($cmd)
 {
     $stdout = ssh2_exec($this->connection, $cmd . '; echo "__RETURNS__:$?"', 'ansi');
     $stderr = ssh2_fetch_stream($stdout, SSH2_STREAM_STDERR);
     stream_set_blocking($stderr, true);
     $this->lastError = stream_get_contents($stderr);
     stream_set_blocking($stdout, true);
     $this->lastOutput = stream_get_contents($stdout);
     $returnCode = null;
     $pos = strpos($this->lastOutput, '__RETURNS__:');
     if (false !== $pos) {
         $returnCode = substr($this->lastOutput, $pos + 12);
         $this->lastOutput = substr($this->lastOutput, 0, $pos);
     }
     return $returnCode;
 }
开发者ID:skedone,项目名称:DeployBundle,代码行数:16,代码来源:PeclSsh2Proxy.php

示例15: exec

 public function exec()
 {
     if (ssh2_auth_password($this->connection, 'root', 'root')) {
         $stream = ssh2_exec($connection, "ls -al");
         $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
         // Enable blocking for both streams
         // stream_set_blocking($errorStream, true);
         stream_set_blocking($stream, true);
         // Whichever of the two below commands is listed first will receive its appropriate output.  The second command receives nothing
         echo '<pre>';
         var_dump(stream_get_contents($stream));
         echo '</pre>';
         // echo "Error: " . stream_get_contents($errorStream);
         // Close the streams
         fclose($stream);
     }
 }
开发者ID:syu93,项目名称:blueShell,代码行数:17,代码来源:Shell.php


注:本文中的ssh2_fetch_stream函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。