I just got some help in automating my password input during an SFTP connection by using Expect.
I then tried to issue a put command and things got complicated again. I'm using the following code:
expect -c "
spawn sftp remoteuser@*.*.*.*
expect \"remoteuser@*.*.*.*'s password:\"
echo "put output/data.xml\r"
I understand you need some help, but you should at least try doing some reading. When you say
expect -c 'some stuff ...', you are specifying the entire expect script as the parameter to the
-c option. The Expect session will not exist afterward.
Also, try to understand what the
interact command does instead of blindly applying what someone advises.
Anyway, the solution:
expect <<'END_EXPECT' set timeout -1 spawn sftp firstname.lastname@example.org expect "[Pp]assword:" send "passwrd\r" expect "whatever the sftp prompt looks like" send "put output/data.xml\r" expect "whatever the sftp prompt looks like" send "quit\r" expect eof END_EXPECT
Note that the here-doc delimiter is quoted when you first see it. That way, you will not be subjected to any shell expansions. It's like the entire here-doc is single-quoted.