weixin_40147370 2019-08-23 10:04 采纳率: 0%
浏览 952

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时间也不会报超时错误,就一直卡在这里

  • 写回答

4条回答

  • 毕小宝 博客专家认证 2019-08-23 14:07
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符