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"

  • 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.

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

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"

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.


Sftp can work without password using

pubkey auth = very safe strong encryption
kerberos = need server,encryption is not strong

Otherwise use expect to send password,WARNING! The pass is visible using ps so this solution is totally unsafe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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