2016-09-20 59 views
2

我试图处理消息时,新的IP /服务器被登录到自动连接,这是我到目前为止有:处理服务器验证的正则表达式SSH读

$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 '|' 

你能帮我解决这个问题吗?或者重写它来让它工作?任何的建议是有帮助:)

+0

这似乎是 “|”在$ read变量发出这个问题。它实际上是否有助于您使用的功能? –

+0

是的,这是造成这个问题,我需要它读取“密码”或“你确定你想继续连接”。 – LeeBronwin

+1

使用'$ this-> ssh-> read('/ Password:|是否确定要继续连接/',NET_SSH2_READ_REGEX);' –

回答

2

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

使用,说,

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