I always used the "proper" solution, but I used expect in other situations.
Here I found following suggestion:
#!/usr/local/bin/expect
spawn sftp -b cmdFile user@yourserver.com
expect "password:"
send "shhh!
";
interact
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…