0
spawn scp USER1@XX.XX.XX.XX:/home/USER1/file.txt USER2@YY.YY.YY.YY:/home/USER2
while {1} {                                      
                                                 
  expect {                                       
                                                 
    eof                          { break }       
    "The authenticity of host"   { send "yes\r" }
    "Password:" { send "PWD1\r" }          
    "Password:" { send "PWD2\r" }          
  }                                              
}     
Bodo
  • 9,287
  • 1
  • 13
  • 29
  • 1
    Instead of feeding passwords into `scp` I suggest to set up public-key authentication. You can also disable the host key check, see https://stackoverflow.com/a/3664010/10622916 – Bodo Mar 10 '21 at 09:01
  • Do both hosts have _exactly_ the same password prompt? Is there no way to differentiate them? – glenn jackman Mar 10 '21 at 14:53

0 Answers0