i want to sftp to a server

Hi all,
I want to sftp to a server called serverB. I want to do it via a running a script. The code i have written is that..

sftp -v x.x.x.x << EOF
user username password
cd dir1
bin
mget *
bye
EOF

But it is not at all working and even it is asking for password. Can any one help me regarding this.

Thank U
Naree

If you do a search of these forums on sftp you will find many postings on this subject. You can only use sftp in interactive mode. For scripting you might try using expect.

Another option would be if you are getting the entire contents of the directory, like in your example, is just to do an scp -r on that directory. Then you would get it all and it a one line command and easily scriptable. Also better to set up pub/priv keys for SSH too instead of putting the user name and password in the script.