Sftp commands not working in shell script

hi,

i am having 2 linux boxes as source and 1 linux box as destination.i want to create a shell script containing code to transfer a csv file from either of the 2 linux boxes (file will be present in just one box, i need to check both the boxes to see which box has the csv file) to 3rd linux box using sftp. suppose i am running this script from 3rd linux box, based on searches i have written the following script.

#/bin/sh
sftp username@host1ip
cd remote_host_file_path
mget filename
rm filename
quit
cd home_path
mv filename path_where_file_needs_to_be_copied

sftp username@host2ip
cd remote_host_file_path
mget filename
rm filename
quit
cd home_path
mv filename path_where_file_needs_to_be_copied

when i run this script through command prompt i get an error like this:

cannot find mget or mget not a command
cd not a command
rm not a command

if i give any echo command in this it is printing the echo value.can someone please help me out with this script. i have verified the keys..so it doesnt ask me to enter the password for connecting to remote host. also when i am running all the commands one by one from command prompt the script is working absolutely fine.

sftp does not read the script, but you can redirect input:

sftp username@host1ip <<!
cd remote_host_file_path
mget filename
rm filename
!

set up trust with PPKeys so no password is necessary, or (bad choice, password security issues) run it under expect, as password is read from /dev/tty not stdin. I bet sftp has options like ftp to make it more script friendly . . . . sftp(1) [opensolaris man page]