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

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 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM