# Using scp file transfer (transfer from the file server A to server B)
#!/usr/bin/expect
set timeout -1
spawn scp A_path B_username@B_IP:B_path
expect {
"password" {send "$B_password\r";}
"yes/no" {send "yes\r";exp_continue}
}
expect eof
exit
# Using scp file transfer (download files from the server B to server A)
#!/usr/bin/expect
set timeout -1
spawn scp B_username@B_IP:B_path A_path
expect {
"password" {send "$B_password\r";}
"yes/no" {send "yes\r";exp_continue}
}
expect eof
exit
If the output contains ## yes / no, said the first time logging in, you need to enter yes to add trusted. Continue this cycle represents exp_continue