<?php
// Copies file from remote host:
ini_set ("expect.timeout", 30);
$stream = fopen ("expect://scp user@remotehost:/var/log/messages /home/user/messages.txt", "r");
$cases = array (
array (0 => "password:", 1 => PASSWORD),
array (0 => "yes/no)?", 1 => YESNO)
);
while (true) {
switch (expect_expectl ($stream, $cases))
{
case PASSWORD:
fwrite ($stream, "password\n");
break;
case YESNO:
fwrite ($stream, "yes\n");
break;
case EXP_TIMEOUT:
case EXP_EOF:
break 2;
default:
die ("Error has occurred!\n");
}
}
fclose ($stream);
?>