2013-09-02 2 views
2

scp 명령을 실행하고 일부 파일을 제공하는 PHP 스크립트를 만들려고합니다. 문제는 명령에 "예/아니오"라는 질문과 암호가 필요하다는 것입니다. 스크립트에서 전달하는 방법을 알 수 없습니다.PHP proc_open 함수에 대한 답변을 전달하는 방법은 무엇입니까?

내 코드 :

$command = "scp $filename {$config['Username']}@{$config['Server']}:{$config['Basedir']}"; 
echo $command; 

$descriptorspec = array(
    0 => array("pipe", "r"), // stdin is a pipe that the child will read from 
    1 => array("pipe", "w"), // stdout is a pipe that the child will write to 
    2 => array("file", sys_get_temp_dir() . "/error.txt", "w"), // stderr is a file to write to 
); 

$cwd = sys_get_temp_dir(); 
$env = array(); 
$process = proc_open($command, $descriptorspec, $pipes, $cwd, $env); 
fwrite($pipes[0], "yes\n"); 
fwrite($pipes[0], $config['Password'] . "\n"); 
proc_close($process); 

이 작동하지 않습니다. 스크립트에서 "계속 연결 하시겠습니까 (예/아니오)?")라는 질문을받습니다. 때마다.

답변

1

이는 알려진 호스트 파일에 나열되어 있지 않은 원격 서버에 연결하기 때문에 보안 확인 사항입니다. ssh 또는 scp 연결을 수동으로여십시오. ssh가 원격 서버의 키를 수락하도록 요청할 것입니다. 그 후에 당신의 명령이 효과가 있습니다.

ssh 일괄 처리를 수행하는 데 도움이되는 옵션도 있습니다.

-oStrictHostKeyChecking=[yes|no] 
-oUserKnownHostsFile=[/dev/null] 

나는 이것을 권장하지 않습니다. ssh는 아주 아주 좋은 이유를 묻습니다!

관련 문제