我正在尝试制作将执行 scp 命令并传递一些文件的 php 脚本。问题是该命令需要回答“是/否”问题和密码。我不知道如何从脚本中传递它。
我的代码:
$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);
这没用。脚本问我“你确定要继续连接(是/否)吗?” 每次。