Sftp connection with password

I am running this script to copy pattern files in local but it is asking for password even passing the hardcode value

Script:-

PASSWORD="xyz"
sftp -oport=1002 user@host:/dir/archive/file*.txt  /di/data/
<< EOF
$PASSWORD
quit
EOF

Got error :-

-bash-4.1$ sh sftp_with_password.sh
Connecting to user@host...
Password Authentication

Please suggest on this.

Embedding passswords in clear text in scripts is bad practise and ssh/sftp is designed to prohibit such usage.

The first approach to take is to generate an SSH-Key and deposit the public key part in target hosts $HOME/.ssh/authorized_keys file.

ssh-keygen
...
ssh-copy-id user@host

If that does not work, try to find the error why.

I don't have access to right SSH file. It is the only way to use hardcode

Did you really try to write the file with sftp?

---

In case there's really no way, you may use sshpass for that case....

The source is located here:

SourceForge - sshpass

Major Linux Linux distributions have that package included.

While using sshpass, it shows command not found
Do I need to install package and will it impact other job ?

On the target server, can you use the credentials your have to sign in and look in the home directory for a .ssh directory? What permission do you have on that directory and particularly the authorized_keys file.

Robin