sftp syntax in script

I am have FTP syntax like below in my bash shell script

ftp -n <<END
        open $Server
                  user $FtpUser $FtpPwd
                  cd $FtpPath
                  binary
                  put $Filename.gz
        bye
END

Now I wanted to change this into SFTP. I tried with this... but fails
Can I have correct SFTP shell script code ?

ftp -n <<END
        open $Server
                  user $FtpUser $FtpPwd
                  cd $FtpPath
                  binary
                  put $Filename.gz
        bye
END

Thanks in advance
sbmk

What did you try so far on your own?
Also we just had it in another thread that it might be (if possible for your environment) better to create passwordless public keys, exchange them to your needs and do the transfer via scp which has the same syntax as rcp. Check this out:

Here is the syntax for an SFTP setup that I created that reads the commands out to a temp file and then runs the SFTP using the tmp file and removes. You could always keep the batch files as well, but I didn't want to have to manage tons of them. You need Passwordless Pubkey authentication though.

I bolded the part below. I don't believe SFTP can read teh STDIN like FTP scripts, but I could be mistaken.

#!/bin/bash

#SFTP_PUSH.sh
#
#       This script is for copying files from location where
#       they are dropped to SFTP server
#
#       Author: Mark Jones
#
#       Last updated: 10/12/09

#Before implementing you can run the create_dirs script to create the archive and log directories

##### Update information below ####
CLIENT=       #client name for directory location
FEEDNAME=     #feed name for directory location
ORIGLOC=  #pickup location
DESTSERV=  #destination server name
DESTUSER=    #username for destination server
DESTLOC=/

#### End User input ####
ARCHLOC=/ftp_custom/archives/$CLIENT/$FEEDNAME
LOGFILE=/ftp_custom/logs/$CLIENT/$FEEDNAME.log
GETDATE=`date`


#       echo start date to log

echo "Started script at $GETDATE" >> $LOGFILE

# Check if items in directory then execute, else (at bottom) exit

if [ "$(find $ORIGLOC -type f)" ]; then


#       List files out to log

echo " The following file was found and is about to be transferred..." >> $LOGFILE

ls -l $ORIGLOC >> $LOGFILE

#       Copy files to archive location

cp -p $ORIGLOC/* $ARCHLOC >> $LOGFILE

#       Copy files to new location using temporary sftp batch file

cd $ORIGLOC
echo cd $DESTLOC > /tmp/$FEEDNAME.sftp
echo 'mput *' >> /tmp/$FEEDNAME.sftp
echo bye >> /tmp/$FEEDNAME.sftp
sftp -b /tmp/$FEEDNAME.sftp $DESTUSER@$DESTSERV >> $LOGFILE
if [ $? -eq "0" ]; then
        echo Files successfully transfered at $GETDATE >> $LOGFILE
        rm -f $ORIGLOC/* >> $LOGFILE
else
        echo File transfer failed at $GETDATE >> $LOGFILE
fi

rm -fv /tmp/$FEEDNAME.sftp

# Echo finish date to log
echo "Finished script at $GETDATE" >> $LOGFILE
exit 0
 # End Script if directory empty
        else
        echo "No files to process $GETDATE" >> $LOGFILE
        echo "Finished script at $GETDATE" >> $LOGFILE
        exit 0
        fi

Hi
this sftp code works as expected.

sftp $FtpUser@$Server <<END
cd $FtpPath
binary
put $Filename.gz
bye
END

Thanks
sbmk

sbmk, I wouldn't mind updating my script to incorperate this, but is tehre a way to send the output to log using this way?