amend ftp to sftp

Hi all, below is my current script

ftp -n << FTPCTRL
 open $my_ip
 user $my_user $my_pass
 ascii
 prompt off
 lcd $myDIR
 cd $ftp_cd
 $OPS $myfile
FTPCTRL

I'd like to amend it to sftp mode. Please advise the correct step.I consulted the man pages of sftp and I suppose I should be using the sftp -b option.

 sftp -b $batchfile $my_user@remotehost << FTPCTRL .. ..

what should I be storing in my batch file? I'd like to retain my use of the variables $my_user and $my_pass,$myDIR,$ftp_cd,$OPS(get or put),$my_file because they are passed in from another script

put all of your commands in the batch file. do not use the HERE document. you can exclude the open/user commands also. sftp is already using this on the command line. You will be prompted for the password. If this is a problem then I would suggest that you setup a ssh key. this is the best way for an automated script.

If you want to use a variable in the batch file then I would suggest generating the batch file and then call it with sftp