Respond y(es) to psftp host key prompt

GaneshT picture GaneshT · Sep 28, 2011 · Viewed 49k times · Source

I am creating a script file programmatically and call psftp.exe as follows:

psftp [email protected] -pw password -b psftpscript.txt

but it prompts for user input

The server's host key is not cached in the registry. You have no guarantee that the server is the computer you think it is. The server's rsa2 key fingerprint is: [ssh-rsa 1024 somekey] If you trust this host, enter "y" to add the key to PuTTY's cache and carry on connecting. If you want to carry on connecting just once, without adding the key to the cache, enter "n". If you do not trust this host, press Return to abandon the connection. Store key in cache? (y/n)

I need it to be completely prompt free, automatic. I tried -batch parameter but it just abandons the connection

Answer

vmitchell85 picture vmitchell85 · Jan 21, 2013

I had the same problem with running a unattended script in Windows Server 2008's 'sandbox' like environment. I ended up running the following which enters the y at the prompt for you:

echo y | psftp [email protected] -l username -pw password -b psftpscript.txt

Hope this helps!

Note: I only had to run the echo y once and removing it for the 2nd run didn't ask for the key to be cached anymore.