Sftp equivalent to ftp -n

Hi all.

I can put ftp command in shell script together with the password using

ftp -n 10.1.2.34 << EOF
user userid password
cd /test_dir/
prompt
bin
get filename.txt
EOF

But the -n option is not available for sftp.

What alternatives do I have then to bypass the password prompt?

Thank you.

Use ssh keys or an expect wrapper. You could also use lftp with the -u username,password option.

1 Like

Thanks murphy.

Have tried both.

expect not found.
lftp also not found.

can I as a normal user install them?

Thank you.

Have you tried keys yet?

Tried.

But it does not work.

Not unless you have root privileges or build then from source.

As Corona688 mentioned using public/private key pairs will be the most secure, Can you give details of why it didn't work(i.e. errors) after you setup the key pairs on each host?

Example use:

sftp -b /dev/stdin -v -o BatchMode=yes -o IdentityFile=/export/home/user/.ssh/id_rsa -o Port=22 user@host <<ENDSFTP
cd /home/user/test
put /export/home/user/test/test.txt test.txt.xferring
rename test.txt.xferring test.txt
quit
ENDSFTP
rc=$?
if [[ $rc != 0 ]]    then
    print "Error occured...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
else
 print "Successful transfer...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
fi