Eu escrevi o seguinte script expect
para isso, e funciona (na minha vms).
Exemplo de execução:
./scp.exp <first host user> <first host user pass> <first host name> <second host name> <second host user> <second host user pass> <directory path i.e. /tmp>
Script:
#!/usr/bin/expect -f
# ./sshlogin.exp uptime
# set Variables
set user [lindex $argv 0];
set password [lindex $argv 1];
set host [lindex $argv 2];
set copy_to_host [lindex $argv 3];
set copy_to_host_user [lindex $argv 4];
set copy_to_host_pass [lindex $argv 5];
set copy_to_host_dir [lindex $argv 6];
set file1 one.txt;
set file2 two.txt;
set timeout 10
# now ssh
spawn ssh $user@$host -o StrictHostKeyChecking=no
match_max 100000 # Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
expect "*$ "
send -- "scp -o StrictHostKeyChecking=no $file1 $file2 $copy_to_host_user@$copy_to_host:$copy_to_host_dir\r"
expect "*?assword:*"
send -- "$copy_to_host_pass\r"
expect "*$ "
send -- "exit\r"
expect eof
Nota: talvez seja necessário adicionar algum tempo de espera para expect
ao lidar com arquivos grandes.