Oh, you want to give a plaintext password in the script, thus bypassing all security? Well... sftp requires a terminal. So, give it one:
#!/usr/bin/expect
set timeout -1
set password [lindex $argv 0 ]
set account [lindex $argv 1 ]
set script [lindex $argv 2 ]
log_file /home/dir/sftp.log
spawn /usr/bin/sftp -C -b $script $account
expect "assword:"
send -- "$password\r"
send -- "\r"
expect eof
Using public key cryptography instead is of course recommended as it is
- safer
- simpler to implement
- not your Fault (plaintext passwords can become)