Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like create a script in HP-UX to send in sftp with password. I have this command

sftp -o PasswordAuthentication=

but if I answer yes or no after, I have this issue "Host key verification failed"

share|improve this question
however you don't have paassword, but i think password is mandatory in this option. – PersianGulf Oct 3 '13 at 12:45
try adding -o StrictHostKeyChecking=no if security implications are acceptable... – jon Oct 3 '13 at 12:49
I'm probably misunderstanding the question, but PasswordAuthentication has a mandatory argument, you should probably use sftp -o PasswordAuthentication=yes ... . – peterph Oct 3 '13 at 14:33

If you have socat handy, there's this example in the manual that you could use.

   (sleep 5; echo PASSWORD; sleep 5; echo ls; sleep 1) |
   socat - EXEC:'ssh -l user server',pty,setsid,ctty

          EXEC’utes an ssh session to server. Uses a pty for communication
          between socat and ssh, makes it ssh’s controlling tty
          (ctty), and makes this pty the owner of a new process group 
          (setsid), so ssh accepts the password from socat.
share|improve this answer

I think it would be better if you use passwordless authentication if you're using SFTP on a script. It is possible, I use it when SFTPing between IBM AIX boxes.

share|improve this answer

It would be better to use public/private key authentication, but in case you still want to use the password in your plain text script, I would use lftp. It is a great client that allows ftp, sftp, ftps connections, you will only need to use 'here document' for the complete transaction:

lftp sftp://your.destination.sftp -u yourUser,YourPassword << fin
    get yourfile
share|improve this answer

you can try below sftp script with using username,password and destip.

spawn sftp username@destip
expect "username@destip's password:"
send "passwd\n"
expect "sftp>"
send "get filename\n"
expect "sftp>"
send "bye\n"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.