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"
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 bye fin
you can try below sftp script with using username,password and destip.
#!/usr/bin/expect 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.