JSCH: SFTP. Hangs at session.connect() using the port 21

Viewed 23499

I am connecting to FTP server via sftp(JSCH).

Evertime i connect to the FTP server using the port 21, it always hangs at session.connect().

It does not throw any exception. But when i use other ports. It works and it throws exception.

Is there any way i could catch the error?

Here is a sample of my code.

public static void main(String[] args) throws SftpException {

    JSch jsch = new JSch();

    try {

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

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

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

    }

}
4 Answers
Related