Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 842669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:59:59+00:00 2026-05-15T05:59:59+00:00

Under my project, I have a Java class file, inside of which I have

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:00:00+00:00Added an answer on May 15, 2026 at 6:00 am

    The reason the host key would fail to verify on one machine and not on another is because one machine will have connected before and another not. If the machine hasn’t connected to the host before, it won’t have the host key to verify against. The host key can fail to verify for a number of reasons – for malicious reasons, like someone is engaging in a man-in-the-middle attack, and for non-malicious reasons like the hostname of the remote machine has changed.

    The way to fix it is to remove the line from your known_hosts file in ~/.ssh

    On a side note, you do know that you don’t have to shell out for SFTP/SCP? JSch exists and will let you use SFTP/SCP in Java. You should probably do this because it’ll work on non-Unix platforms like Windows and you have a bit more control over things like known_hosts. It’s pretty easy to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 410k
  • Answers 410k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Q1: It is better to use an int as a… May 15, 2026 at 7:34 am
  • Editorial Team
    Editorial Team added an answer You need to set the output method to text instead… May 15, 2026 at 7:34 am
  • Editorial Team
    Editorial Team added an answer How about this: $('span.gallery-open-item.year-icon-Yes > a').each(function(i, elem) { $.each($(elem).parent().attr('class').split(' '),… May 15, 2026 at 7:34 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.