I'm getting a java.net.ConnectException: failed to connect to 192.168.2.100 (port 22): connect failed: ECONNREFUSED (Connection refused) when connecting to a server via SSH with JSCH-0.1.54 on Android.
The firewall is configured to let the IP adress through. SSH connection from Windows to the server is possible via Putty. The server's IP adress is alright.
What else can it be?
The code I'm using is below:
protected Long doInBackground(String... params)
{
try
{
System.setProperty("http.keepAlive", "false");
JSch jsch = new JSch();
Session session = jsch.getSession("root", "192.168.2.100", 22);
session.setPassword("Password");
session.setTimeout(10000);
Properties props = new Properties();
props.put("StrictHostKeyChecking", "no");
session.setConfig(props);
session.connect();
ChannelExec channel = (ChannelExec) session.openChannel("exec");
if(params[0]=="poweroff")
{
LogPublic("Server wird heruntergefahren");
}
else if(params[0]=="reboot")
{
LogPublic("Server wird neugestartet");
}
channel.setCommand(params[0]);
channel.connect();
channel.disconnect();
session.disconnect();
jsch.removeAllIdentity();
jsch = null;
return new Long(1);
}
catch (Exception ex)
{
LogPublic(ex.getMessage());
return new Long(0);
}
}
The solution was to set the server's static IP address out of my router's DHCP range as this caused an IP conflict.