Lftp sftp get - script renames the local file with suffix tilde

Hi,
Below script used for sftp get,

#/bin/bash
USER=xxx
PASS=xxx
HOST=xxx
REMOTE_FILE=$1
LOCAL_FILE_LOC=$2
cd $LOCAL_FILE_LOC
lftp sftp://$USER:$PASS@$HOST:10022 -e "get $REMOTE_FILE; bye"

If file does not exist in sftp server, and file (same as remote file name) exists in local dir, above script throws error and renames local file with suffix ~ .
For example: If file name is xyz_file after script execution it throws error:

get: Access failed: /xyz_file: Specified file path is invalid. and renames the local file to 'xyz_file~'

Any idea why its happening.

It looks like you're calling your script with /xyz_file as the 1st operand and /xyz_file either does not exist on the host or, if it does exist, you don't have permission to read it.

Yes. file does not exit in server. But why command renames the local file with suffix tilde? 'xyz_file~'

It does that because the software you're running assumes that it will be replacing an existing file and makes a backup copy before checking whether or not there is a file to copy.

I would consider that assumption a bug; it seems to me that it should at least move the file back to its original name if it couldn't transfer any data. But, I'm not familiar with lftp . What does its man page say it will do in this case?

Thanks.
As per Man page, xfer:make-backup (boolean) : when true, lftp renames pre-existing file adding �~� suffix instead of overwriting it.
Default value for above variable is �yes�. So before executing the get command disable the backup option for the current session.

lftp sftp://$USER:$PASS@$HOST:10022 -e "set xfer:make-backup no; get $REMOTE_FILE; bye"

It worked.