sisko
sisko

Reputation: 9910

Why does automating SFTP with Expect hang after sending the password?

I am attempting to automate uploading some files from my Linux server to an FTP-enabled Windows server. I am successfully doing so manually using SFTP and then issuing the put command. However, when called from cron, my script keeps stopping for a password.

Below is the code I am attempting to use:

#!/usr/bin/expect
#!/bin/sh
clear
spawn sftp [email protected]
expect "password"
send "world"
expect eof

As it stands, it stops each time to request a password. Why doesn't send "world" complete the password dialog?

UPDATE:

#!/usr/bin/expect
#!/bin/sh
clear
spawn sftp [email protected]
expect "[email protected]'s password:"
send "world"
expect eof

Now I get the following error:

xml_reports.sh: line 5: spawn: command not found
couldn't read file "[email protected]'s password:": no such file or directory
xml_reports.sh: line 7: send: command not found
couldn't read file "eof": no such file or directory

Upvotes: 1

Views: 6230

Answers (3)

Suku
Suku

Reputation: 3880

Try like this:

#!/bin/bash
expect -c "
spawn sftp [email protected]
expect \"password\"
send \"PASSWORD\r\"
interact "

Example : http://www.techtrunch.com/scripting/lazy-admins-part-2

Upvotes: 4

Omirp
Omirp

Reputation: 52

What is happening is Expect is still waiting for the pattern to arrive (until timeout), it could be that "password" is not in the prompt of sftp and that it could be "Password" or something else.

Upvotes: 0

user1943931
user1943931

Reputation:

You need to use arguments when you run it. Read this article. It explains how to do this properly.

Upvotes: 0

Related Questions