1753852 Members
7754 Online
108807 Solutions
New Discussion юеВ

Expect and SFTP

 
SOLVED
Go to solution
David L Brewster
Frequent Advisor

Expect and SFTP

I am using sftp to transfer files to/from a remote system. That remote system is the government, so we are not exchanging ssh keys.
I am being prompted for a password each time and would think I can use "expect" to put this in my batch script. However, I am new to expect and cannot find an example on how to use this. man pages for expect didn't really help. Does anyone have an example on how to pass the password to sftp using expect?
Thanks,
Dave
5 REPLIES 5
Stephan._1
Trusted Contributor
Solution

Re: Expect and SFTP

HI,
never used it before but perhaps http://www.unix.com/shell-programming-scripting/21466-automating-sftp-expect.html helps you
Share what you know, learn what you don't.
James R. Ferguson
Acclaimed Contributor

Re: Expect and SFTP

David L Brewster
Frequent Advisor

Re: Expect and SFTP

Yes and Yes!
Both worked great.
I was unsure of syntax, but examples you sent cleared it up. Also noted some gotcha's.
Thanks to you both.

Dave
rhansen
Frequent Advisor

Re: Expect and SFTP

Hello David,

I have a similar project, do you mind sharing your scripts to me please.

Thanks in advance.
David L Brewster
Frequent Advisor

Re: Expect and SFTP

Here is what I have:

#!/usr/local/bin/expect --

set timeout 200

spawn /usr/bin/sftp -oPort=10022 username@sftp.11.22.33.gov
expect "username@sftp.11.22.33's password:"
send "password\r"
expect "sftp> "
send "lcd /tmp/ \r"
expect "sftp> "
send "get file \r"
expect "sftp> "
send "bye \r"