In my project, I have a Java class file inside which I have a routine that 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 that executes the script file is as follows:
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 check. Connection closed. "
I highlighted this line in a script that was connected to the remote machine and ran it on the local computer (where this class file and script are stored), and the command completed successfully
I would manually execute the command that the Java class file executed, and it also passed the test:
$ script.sh param1 param2 param3
, , , - known_hosts. , - , ?
!