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


PHP ssh2_exec函数代码示例

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


在下文中一共展示了ssh2_exec函数的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: coneccionSshImg

 function coneccionSshImg($ids, $mBanner, $config)
 {
     $porciones = explode(",", $ids);
     foreach ($porciones as $value) {
         $dataBanner = $mBanner->select($value);
         $avanzado = ROOT_IMG_DINAMIC . '/banner/avanzado/' . $dataBanner["ImgAvanzado"];
         $basico128 = ROOT_IMG_DINAMIC . '/banner/basico128/' . $dataBanner["ImgBasico128"];
         $basico240 = ROOT_IMG_DINAMIC . '/banner/basico240/' . $dataBanner["ImgBasico240"];
         $basico360 = ROOT_IMG_DINAMIC . '/banner/basico360/' . $dataBanner["ImgBasico360"];
         if (!function_exists("ssh2_connect")) {
             die("function ssh2_connect doesn't exist");
         }
         if (!($con = ssh2_connect($config['app']['server'], $config['app']['puerto']))) {
             echo "fail: unable to establish connection\n";
         } else {
             if (!ssh2_auth_password($con, $config['app']['user'], $config['app']['pass'])) {
                 echo "fail: unable to authenticate\n";
             } else {
                 ssh2_scp_send($con, $avanzado, $config['app']['rutaImg'] . 'banner/avanzado/' . $dataBanner["ImgAvanzado"], 0644);
                 ssh2_scp_send($con, $basico128, $config['app']['rutaImg'] . 'banner/basico128/' . $dataBanner["ImgBasico128"], 0644);
                 ssh2_scp_send($con, $basico240, $config['app']['rutaImg'] . 'banner/basico240/' . $dataBanner["ImgBasico240"], 0644);
                 ssh2_scp_send($con, $basico360, $config['app']['rutaImg'] . 'banner/basico360/' . $dataBanner["ImgBasico360"], 0644);
             }
             ssh2_exec($con, 'exit');
         }
     }
     return;
 }
开发者ID:josmel,项目名称:movistar,代码行数:28,代码来源:SetBannerGroup.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: sync_logos

 function sync_logos()
 {
     if ($this->ssh2_connection) {
         debug("Syncing logos");
         ssh2_exec($this->ssh2_connection, "/bin/rsync_scripts/download-content-partners.cgi");
     }
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:7,代码来源:SSH2Connection.php

示例5: conn_close

 protected static function conn_close($conn)
 {
     if (ssh2_exec($conn, 'exit') === false) {
         return false;
     }
     return true;
 }
开发者ID:Rudi9719,项目名称:stein-syn,代码行数:7,代码来源:SftpStream.php

示例6: 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

示例7: get_list

function get_list($myhost, $usern, $passw, $mypath, &$data)
{
    if (!function_exists("ssh2_connect")) {
        die("function ssh2_connect doesn't exist");
    }
    if (!($conn = ssh2_connect($myhost, 22))) {
        echo "fail: unable to establish connection\n";
    } else {
        if (!ssh2_auth_password($conn, $usern, $passw)) {
            echo "fail: unable to authenticate\n";
        } else {
            if (!($stream = ssh2_exec($conn, "ls -1 " . $mypath))) {
                echo "fail: unable to execute command\n";
            } else {
                stream_set_blocking($stream, true);
                // allow command to finish
                $data = "";
                while ($buf = fread($stream, 4096)) {
                    $data .= $buf;
                }
                fclose($stream);
            }
        }
    }
    ssh2_exec($conn, 'exit');
}
开发者ID:AdamDS,项目名称:GenomeVIP,代码行数:26,代码来源:listfiles_real_json_key2.php

示例8: ssh

 public function ssh()
 {
     if (!function_exists("ssh2_connect")) {
         die("function ssh2_connect doesn't exist");
     }
     // log in at server1.example.com on port 22
     if (!($con = ssh2_connect("nao.local", 22))) {
         echo "fail: unable to establish connection\n";
     } else {
         //try to authenticate with username root, password secretpassword
         if (!ssh2_auth_password($con, "nao", "nao")) {
             echo "fail: unable to authenticate\n";
         } else {
             // allright, we're in!
             echo "okay: logged in...\n";
             // execute a command
             if (!($stream = ssh2_exec($con, "ls -al"))) {
                 echo "fail: unable to execute command\n";
             } else {
                 // collect returning data from command
                 stream_set_blocking($stream, true);
                 $data = "";
                 while ($buf = fread($stream, 4096)) {
                     $data .= $buf;
                 }
                 fclose($stream);
             }
         }
     }
 }
开发者ID:Cydev2306,项目名称:Nao-App,代码行数:30,代码来源:Ssh.php

示例9: execute

 /**
  * 执行远程命令。
  * 
  * @param string $command 指定命令字符串。
  * @return resource|boolean
  * @throws NetworkException
  */
 function execute($command)
 {
     if (!$this->shell_ok) {
         throw new NetworkException('尚未连接远程主机。', -1);
     }
     $r = ssh2_exec($this->shell_session, $command);
     return $r;
 }
开发者ID:heesey,项目名称:LeePHP-Socket,代码行数:15,代码来源:Shell.php

示例10: execute

 function execute($command, $pty = null, array $env = array(), $width = 80, $height = 25, $width_height_type = SSH2_TERM_UNIT_CHARS)
 {
     $stream = ssh2_exec($this->ssh, $command, $env, $width, $height, $width_height_type);
     if (false === $stream) {
         throw new SSHException('Couldnt execute command, no stream returned');
     }
     stream_set_blocking($stream, true);
     return stream_get_contents($stream);
 }
开发者ID:splitice,项目名称:radical-net,代码行数:9,代码来源:Connection.php

示例11: doExec

 public function doExec($obj, $out_cb)
 {
     if (empty($this->_cmd)) {
         throw new \Exception('cmd is invaild');
     }
     $stream = ssh2_exec($this->_ins, $this->_cmd);
     stream_set_blocking($stream, true);
     call_user_func_array(array($obj, $out_cb), array($stream));
 }
开发者ID:peterxiemin,项目名称:commonswoole,代码行数:9,代码来源:SShWrapper.php

示例12: command

 public function command($command)
 {
     $stream = ssh2_exec($this->connection, $command);
     $this->logs[] = '$ ' . $command;
     stream_set_blocking($stream, true);
     $d = fread($stream, 4096);
     fclose($stream);
     $this->logs[] = $d;
     return $d;
 }
开发者ID:nouphet,项目名称:xoops-tpSocialMedia,代码行数:10,代码来源:Ssh2.php

示例13: killSc_Trans

 public function killSc_Trans($sc_rel_id)
 {
     $PID = \DB::queryFirstRow("SELECT sc_trans_pid FROM sc_rel WHERE id=%s", $sc_rel_id);
     $SSHConf = $this->getSSHConf();
     $connection = ssh2_connect($SSHConf['ip'], $SSHConf['port']);
     ssh2_auth_password($connection, $SSHConf['user'], $SSHConf['pass']);
     ssh2_exec($connection, 'kill ' . $PID['sc_trans_pid']);
     sleep(1);
     $this->setPID($sc_rel_id, '0');
 }
开发者ID:edinsof,项目名称:Ecast,代码行数:10,代码来源:sctrans.php

示例14: _executeStringRemotely

 /**
  * Executes provided command string through an SSH session in a remote terminal.
  * @return String The command's output
  */
 protected function _executeStringRemotely($commandString, Garp_Shell_RemoteSession $session)
 {
     if (!($stream = ssh2_exec($session->getSshSession(), $commandString))) {
         return false;
     }
     stream_set_blocking($stream, true);
     $content = stream_get_contents($stream);
     $this->_bubbleSshErrors($stream, $commandString);
     fclose($stream);
     return $content;
 }
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:15,代码来源:Abstract.php

示例15: run

 private function run($cmd)
 {
     if ($h = ssh2_exec($this->handle, $cmd)) {
         stream_set_blocking($h, true);
         stream_set_timeout($h, $this->timeout);
         $result = stream_get_contents($h);
         fclose($h);
         return $result;
     }
     return false;
 }
开发者ID:laiello,项目名称:litepublisher,代码行数:11,代码来源:remote.ssh2.class.php


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