Sftp some files from windows server to UNIX server

hi

i need to transfer some files from windows server to unix server using SFTP. but before transferring the files, i need to check the
existence of a particular file in the remote directory (say r_dir1). if the file is present, then SFTP all the files.
after SFTPing the files from the remote directory (r_dir1) to unix directory, i need to move the files from remote directory (r_dir1)
to some other remote directory (say dir2) in the same windows server only.

i am using the following code

#! /bin/ksh

TARGET_DIR=<path of target directory>
FILE_NAME_TO_CHECK=<file_name>
REMOTE_USER=<user_name>
REMOTE_MACHINE=<windows server name>
REMOTE_DIR=<path of windows directory>

cd ${TARGET_DIR}

sftp ${REMOTE_USER}@${REMOTE_MACHINE} <<EOF
cd ${REMOTE_DIR}
if [[ -f "$REMOTE_DIR"/"$FILE_NAME_TO_CHECK" ]]; then     
    get *                          # downloading all the files
    mv * <path of the r_dir2>             
else
    echo "$FILE_NAM the E_TO_CHECK doesn't exist so cant copy other files"
fi

--------------------------------------------------------------------------------------------------------------
# files are getting SFTPed to the unix server but

    errors: 
        1:- showing "if" and "else" statements as invalid commands
        2:- showing "mv" command as invalid

please, some body provide me a solution.. i need it urgently

What about reading the man stfp page? No if , no else , no mv , but:

So - check for existence of control file with e.g. ssh ... ls , then get and rename files with sftp .

BTW - your here document is missing its final token (EOF)