Question

This question already has an answer here:

I am trying to copy a file from my remote server to my local. Here's my script to run it, by using 'expect' to automaticlally send in password

scp user@host:/folder/myFile ./
expect "Password: "
send "myPassword"

When I run this, it still prompts for "Password", what is wrong?

Was it helpful?

Solution

From what you are trying to do it sounds like you might be better off using ssh with a public and private key. You could google for ssh-keygen tutorial to get started.

OTHER TIPS

While I agree with Sam and nik, the answer to you questions is that you didn't "hit enter":

send "mypassword\r"

This expect script does the job (thanks to 'zedwood' )

#!/usr/bin/expect -f
set filename [lindex $argv 0]
set timeout -1
spawn scp $filename myusername@192.168.1.123:/home/myusername/
set pass "mypassword"
expect {
        password: {send "$pass\r" ; exp_continue}
        eof exit
}

please do not even leave such scripts around that will be picked up by someone else and used elsewhere.... do try public key authentication, it is are very easy to setup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top