2016-09-20 33 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); 
       ^             ^