how i can use sftp in script

how i can use sftp in script,

 
unset LIBPATH
sftp wccuser@10.77.77.77 <<eof1>> /home/wccuser1/wcc/Scripts/bulk_file_ftp/bulk_file_ftp.log
passwordlcd /home/wccuser1/wcc/Scripts/bulk_file_ftp
cd /wcc_cdr01/misuser/wcc/ftp/log_file_ftp/10.77.0.77
mput  *.csv
bye
eof1

while execution it is promting for password , not taking automatically.

 
 
+ unset LIBPATH
+ sftp wccuser1@10.77.77.77 + 0< /tmp/sh602212.2 1>> /home/wccuser1/wcc/Scripts/bulk_file_ftp/bulk_file_ftp.log
wccuser1@10.77.0.23's password:

ssh, and any other sane login system, does not take plaintext passwords from anything but a terminal. "Interactive password authentication" means "Password typed by a human being in realtime authentication" and no artificial substitutes for humans are acceptable. If you redirect into it, it will just open /dev/tty to get your terminal. If no terminal is available, it will simply quit. This is an important security feature; it's nearly impossible to keep retrievably-stored passwords safe.

The proper way is to use noninteractive authentication, which you can do by creating a key on the client and copying it over to the appropriate place on the server. It will try the key first, and if it's accepted, the login will go through automatically and without fuss. See passwordless ssh -- ssh, sftp, and scp all use the exact same login system and keys etc.

1 Like

k thanks , i will try and let u know in case if it not works.