Question

I am trying to connect to a remote device that I cannot manage via a JSch, although I can connect using WinSCP client with the same credentials.

The application is a J2EE based enterprise application, which runs on JBoss AS 7.1.1, on a Windows server, and I am trying to connect the SFTP server from a Quartz job. The code that I am using to verify SFTP login is below.

try {
    Session session = jsch.getSession("username", "host", 22);
    session.setConfig("StrictHostKeyChecking", "no");
    session.setPassword("password");
    session.connect();

    Channel channel = session.openChannel("sftp");
    ChannelSftp channelSftp = (ChannelSftp) channel;                
    channel.connect();
    session.disconnect();
    channelSftp.disconnect();

} catch (JSchException e) {
    log("Cannot make connection to FTP server ");
    e.printStackTrace();
}

I am getting

com.jcraft.jsch.JSchException: java.net.ConnectException: Connection refused: connect
exception at session.connect();

I am using 0.1.50 version of JSch

Another inconsistency occurs when I ran this code in development environment; I can connect to a server with SFTP.

Can you help me pinpoint the probable cause of this behavior?

Was it helpful?

Solution

The Issue was because of the topology of the network and permissions of the communicating parties. If you face the same problem, please take these issues in to consideration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top