2017-06-27 58 views
0

我有一個可移植的版本的Apache和php7在Windows phpseclib1.0.7。我想擴展lib以便利用ssh。利用從網站股票腳本 測試PHP SSH2:超過30秒的最大執行時間

<?php 
include('Net/SSH2.php'); 

$ssh = new Net_SSH2('-Redacted-'); 
if (!$ssh->login('-Redacted-', '-Redacted-')) { 
    exit('Login Failed'); 
} 

echo $ssh->read('[email protected]:~$'); 
$ssh->write("sudo ls -la\n"); 
$output = $ssh->read('#[pP]assword[^:]*:|[email protected]:~\$#', 
NET_SSH2_READ_REGEX); 
echo $output; 
if (preg_match('#[pP]assword[^:]*:#', $output)) { 
    $ssh->write("password\n"); 
    echo $ssh->read('[email protected]:~$'); 
} 
?> 

即使缺少信息,則應該拋出一個錯誤,而是它給了我

PHP Fatal error: Maximum execution time of 30 seconds exceeded in 
C:\Users\-Redacted-\Desktop\Apache2.2\htdocs\Net\SSH2.php on line 2358 

這裏是SSH2.php開始行2351

if (isset($this->keyboard_requests_responses)) { 
for ($i = 0; $i < $num_prompts; $i++) { 
if (strlen($response) < 4) { 
return false; 
} 
extract(unpack('Nlength', $this->_string_shift($response, 4))); 
// prompt - ie. "Password: "; must not be empty 
Line 2358---- $prompt = $this->_string_shift($response, $length); 
//$echo = $this->_string_shift($response) != chr(0); 
foreach ($this->keyboard_requests_responses as $key => $value) { 
if (substr($prompt, 0, strlen($key)) == $key) { 
$responses[] = $value; 
break; 
} 
} 
} 
} 

沒有人有任何想法如何解決?

+0

你可以ping遠程主機嗎? – apokryfos

+0

是否確定您的服務器ssh open是否打開? –

+0

膩子與遠程主機一起工作得很好。 – MoonEater916

回答

0

我認爲你無法到達www.domain.tld,首先,你必須確保你的系統可以訪問www.domain.tld。 你可以用你的代碼在一個try-catch塊,以得到一個錯誤

<?php 
include('Net/SSH2.php'); 
try{ 
$ssh = new Net_SSH2('-redacted-'); 
if (!$ssh->login('-redacted-', '-redacted-')) { 
    exit('Login Failed'); 
     } 

echo $ssh->read('[email protected]:~$'); 
$ssh->write("sudo ls -la\n"); 
$output = $ssh->read('#[pP]assword[^:]*:|[email protected]:~\$#', 
NET_SSH2_READ_REGEX); 
echo $output; 
if (preg_match('#[pP]assword[^:]*:#', $output)) { 
    $ssh->write("password\n"); 
    echo $ssh->read('[email protected]:~$'); 
}catch(\Exception $ex){echo "You got an error".$ex->getMessage();} 
?> 

如果你確信主機可達可以擴展最大timout這樣的:

ini_set('max_execution_time', 300); 

如果您確定你的主機是正確的,你可以檢查你的主機ssh端口是否打開並且工作正常?

+0

我離開了信息泛型,因爲我不允許發佈連接細節,我可以把主機弄好, – MoonEater916

+0

@ MoonEater916 - 看到PuTTY日誌會很有趣 - 你可以通過PuTTY - > Sess離子 - >記錄和檢查「SSH數據包」單選按鈕。然後照常連接。我有一個想法是什麼問題(其中包括您使用錯誤的PW登錄),但日誌有助於確認這一點。 – neubert

相關問題