I would like to run a local script that when done attempts to send a tarball via SSH to my server and therefore requires a password. Is there a way to use the ssh2 libraries, proc_open or another library to achieve this in PHP.
I understand how to perform terminal commands from within a PHP script, I'm getting stuck when I attempt to send this tarball to my server:
What I have so far
The calling code
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;
}
The command
$this->run('shell_script_i_cannot_change_that_runs_ssh', array('password'));
Error:
Host key verification failed
I cannot change the script, I can only call it from PHP. If there is a solution, can it be PHP only