Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用phpseclib在php中通过SSH正确发送数据_Php_Laravel_Ssh_Phpseclib - Fatal编程技术网

如何使用phpseclib在php中通过SSH正确发送数据

如何使用phpseclib在php中通过SSH正确发送数据,php,laravel,ssh,phpseclib,Php,Laravel,Ssh,Phpseclib,我正试图用php向远程服务器发送命令。问题是,当我尝试发送一个带有参数的命令时,它会将参数与文本连接起来 例如,如果我执行“mmi模式禁用”,它将执行命令ok 但当我尝试发送“undo service port$id_ont”时,它会尝试执行“undo service-port4”而不是“undo service port 4” 执行命令的功能是: protected function execCommand(Command $command) { $response =

我正试图用php向远程服务器发送命令。问题是,当我尝试发送一个带有参数的命令时,它会将参数与文本连接起来

例如,如果我执行“mmi模式禁用”,它将执行命令ok

但当我尝试发送“undo service port$id_ont”时,它会尝试执行“undo service-port4”而不是“undo service port 4”

执行命令的功能是:

protected function execCommand(Command $command)
    {
        $response = '';

        $this->ssh->write("{$command->getCommand()}{$this->enterKey}");

        if ($this->logging) {
            $response = $this->ssh->read();

            $this->log($command->getCommand(), $response);
        }

        if ($command->needResponse()) {
            if ($response === '') {
                $response = $this->ssh->read();
            }

            $this->response($response);
        }
    }
我从服务器得到的响应是

OLT-Belisle01(config-if-gpon-0/0)#\r\n
       \r\n
       OLT-Belisle01(config-if-gpon-0/0)#
       """,
     """
       undo service-port4\r\n
                                              ^\r\n
         % Unknown command, the error locates at '^'\r\n
       \r\n
       OLT-Belisle01(config-if-gpon-0/0)#\r\n
       \r\n
       OLT-Belisle01(config-if-gpon-0/0)#
       """,
你正在做
“{$command->getCommand()}{$this->enterKey}”
-也许你需要做
“{$command->getCommand()}{$this->enterKey}”
?除此之外,您还没有提供足够的信息让任何人真正诊断问题。您可以执行
echo base64\u encode($command->getCommand())
echo base64\u encode($this->enterKey)
并告诉我们它们的输出是什么吗?
base64_encode
将使其成为这样,如果从渲染中复制/粘贴,则不会排除其他不可见的字符。与web浏览器中一样,软连字符基本上是一个不可见字符。