xshell能连上远程sftp,Java内却连不上

有没有大佬能解决下

public static boolean initChannel(String host,Integer port,String userName,String password){
        try {
            JSch jSch = new JSch();
            sshSession = jSch.getSession(userName,host,port);
            sshSession.setPassword(password);

            Properties sshConfig = new Properties();
            sshConfig.put("StrictHostKeyChecking", "no");
            sshSession.setConfig(sshConfig );
            //sshSession.setTimeout(60);
            sshSession.connect();

            Channel channel = sshSession.openChannel("sftp");
            channel.connect();

            sftp = (ChannelSftp) channel;
            return true;
        } catch (JSchException e) {
            e.printStackTrace();
            logger.error("sftp连接失败,host:{},port:{}",host,port,e);
            return false;
        }
    }

打断点发现是卡在sshSession.connect()方法一直过不去,在这段
图片说明
而且设置了timeout时间也不会报超时错误,就一直卡在这里

对比了你的代码和我们开发过程中用的代码,完全一致,不合理的,不管怎么样,最后即使错误也应该有异常才对。
在 return true 之前打一下日志,看看到底执行到哪一步了。
还有,检查下 IP 和端口,sftp 端口是 22 。

1、核对ip、端口、用户名、密码
2、关闭Linux服务器的防火墙

我也是同样的问题,现在卡在这里了。

老哥解决了吗?我也遇到这个问题了。。。