Connecting to SFTP service via Java Runtime process

Posted by ohseekay on Stack Overflow See other posts from Stack Overflow or by ohseekay
Published on 2010-06-07T02:39:38Z Indexed on 2010/06/07 3:02 UTC
Read the original article Hit count: 344

Filed under:
|
|

Under my project, I have a Java class file, inside of which I have a routine which executes the following external SFTP script file:

#!/bin/sh
echo "cd AV/OASIS" >> sftp
echo "put $1 $2" >> sftp
echo "get AV/OASIS/$2 $3$2" >> sftp
echo "bye" >> sftp
/usr/local/bin/sftp -b sftp id@domain
cat /dev/null > sftp
exit 0

The Java code which executes the script file is as below:

String script = "full path of script";
Process p = Runtime.getRuntime().exec(script + " " + param1 + " " + param2 + " " + param3);

However, I'm not sure why, but the log generated by the class file always shows the error "Host key verification failed. Connection closed."

I'd isolated that line in the script which connected to the remote machine, and ran it on the local machine (where this class file and script file are stored), and the command executed successfully

I'd manually run the command which the Java class file will execute and it also tested okay:

$ script.sh param1 param2 param3

I'd tried to look up the error message on the Internet, and apparently it seems to have something to do with known_hosts. Could this be the reason, or is there something else I'm missing?

Thanks so much!

© Stack Overflow or respective owner

Related posts about java

Related posts about sftp