Reputation: 2336
I'm using com.jcraft.jsch.JSch
to create an SFTP connection.
Is there a way to bypass/skip the authenticity warning that pops up when the connection's authenticity can't be established?
Here's more detail:
My code looks a little like this:
Session session = jsch.getSession(user, host, port);
UserInfo ui = new MyUserInfo();
session.setUserInfo(ui);
session.connect();
When the session.connect();
line is called, I get a popup that reads:
The authenticity of host <MY HOST> can't be established.
...
Are you sure you want to continue connecting?
[No] [Yes]
Is there a way to programmatically bypass/skip this popup and accept the connection?
Upvotes: 2
Views: 4073
Reputation: 211
I know this thread is very old and doesn't require any reply if its already solved, But a week back I too was working on an application that had a similar requirement.
What Jon7 said was right; Adding to that theres a different way too i.e. without extending any class.
Session session = jsch.getSession(user, host, port);
...
Properties prop = new Properties();
prop.setProperty("StrictHostKeyChecking", "no");
session.setConfig(prop);
session.connect();
Just another way that can help others :)
regards,
icr
Upvotes: 3
Reputation: 7215
Take a look at these examples from Jsch: http://www.jcraft.com/jsch/examples/Exec.java.html http://www.jcraft.com/jsch/examples/Shell.java.html You'll notice that both of them create a custom UserInfo
class and pass it to the session object with session.setUserInfo(UserInfo ui);
.
The way to avoid that popup window is to pass in your own UserInfo
object. You can do this by extending the UserInfo
class and overriding the promptYesNo
function, like this:
public boolean promptYesNo(String str){ return true; }
Note that all of the functions whose names start with the word "prompt" are used to prompt the user for information with a popup dialog. You can override those functions to pass in the information in some other way.
Upvotes: 4