-1
我想運行一個本地腳本,當完成嘗試通過SSH發送tar包到我的服務器並因此需要密碼時。有沒有辦法使用ssh2庫,proc_open或其他庫來實現這一點在PHP中。PHP運行期望SSH密碼的腳本
我知道如何從PHP腳本中執行終端命令,我被卡住當我嘗試這個壓縮包發送到我的服務器:
我有什麼到目前爲止
主叫代碼
private function run($command, array $arguments = array(), Response $response = null) {
$pipes = array();
$descriptorspec = array(
array('pipe', 'r'), // STDIN
array('pipe', 'w'), // STDOUT
array('pipe', 'w'), // STDERR
);
$process = proc_open($command, $descriptorspec, $pipes, $this->directory);
foreach ($arguments as $arg) {
// Write each of the supplied arguments to STDIN
fwrite($pipes[0], (preg_match("/\n(:?\s+)?$/", $arg) ? $arg : "{$arg}\n"));
}
if (!$response) {
$response = new Response;
}
$response->addCompletedCommand(stream_get_contents($pipes[1]), $command, $arguments);
$error = stream_get_contents($pipes[2]);
if ($error) {
$response->addError($error, $command, $arguments);
}
// Make sure that each pipe is closed to prevent a lockout
foreach ($pipes as $pipe) {
fclose($pipe);
}
proc_close($process);
return $response;
}
命令
$this->run('shell_script_i_cannot_change_that_runs_ssh', array('password'));
錯誤:
Host key verification failed
我不能改變劇本,我只能從PHP調用它。如果有解決方案,是否只能使用PHP
的可能的複製[如何使用bash進入SSH密碼?] (http://stackoverflow.com/questions/16928004/how-to-enter-ssh-password-using-bash) – cmorrissey
@cmorrissey這與php沒有任何關係,並且請注意,我無法更改shell腳本 –
爲什麼你不能更改shell腳本?你可以FTP它http://php.net/manual/en/book.ftp.php,你可以通過CURL等發送它等。 – cmorrissey