处理服务器身份验证正则表达式 SSH 读取

Handling server authentication Regex SSH Read

我正在尝试处理消息以在新 ip/server 登录时自动连接,这是我目前所拥有的:

    $read = $this->ssh->read('(Password:)|(Are you sure you want to continue connecting)', NET_SSH2_READ_REGEX);
            if (preg_match('/Are you sure you want to continue connecting/',$read)) {
                $this->ssh->write('yes');
                $this->ssh->write("\n");
                $this->ssh->read('Permanently added');

                $this->ssh->write('ssh '.$this->userid.'@'.$this->testIPAddress);
                $this->ssh->write("\n");                
                $read = $this->ssh->read('(Password:)|(Are you sure you want to continue connecting)', NET_SSH2_READ_REGEX);
            } else if ($this->ssh->isTimeout()) { 
                $testLineHideResult = "Connection failed";
            }

            if ($testLineHideResult == '') {
                $this->ssh->write($this->passwd);
                $this->ssh->write("\n");
                $this->ssh->setTimeout(25); 

但我收到以下错误消息:

preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Unknown modifier '|'

你能帮我解决这个问题或重写它以使其正常工作吗?任何建议都有帮助:)

重点是 SSH read() 中的正则表达式与 preg_ PHP 函数中应该使用的正则表达式相同,因此需要正则表达式分隔符。您可以在 phpseclib documentation 网页上查看语法。

使用,比方说,

$this->ssh->read('/Password:|Are you sure you want to continue connecting/', NET_SSH2_READ_REGEX);
                  ^                                                      ^