I have written a script that uses sftp to get files. The issue I am having is that it is still prompting me for a password. Before you say my ssh pub/priv key is set up wrong, when I sftp from console I do not have to enter my password. I believe I may have the script wrong. Please advise me.
Problem: Passwordless SFTP works in console but not in script
(SFTP uName@host) on command line connects and loads sftp
Script asks for password
FTPSERVER='server'
USER='uName'
FILEPATH='Path'
FILE1='File.txt'
#SFTP pull to local directory, uses ssh with public key placed on username's .ssh folder
sftp $USER@$FTPSERVER <<EOF
cd $FILEPATH
get $FILE1
bye
EOF