m0_37769150 2018-01-24 06:14 采纳率: 0%
浏览 3609
已结题

sftp遇到的一个bug,报错,急求大神解决

ChannelSftp.ls(String directory)方法,使用中会报异常:
at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1720)
at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1526)
Caused by: java.io.IOException: Pipe closed
at java.io.PipedInputStream.read(PipedInputStream.java:291)
at com.jcraft.jsch.Channel$MyPipedInputStream.updateReadSide(Channel.java:362)
at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1543)

  • 写回答

1条回答 默认 最新

  • fengminfengmin 2018-01-24 06:31
    关注

    public static void downloadSftpFile(String ftpHost, String ftpUserName,

    String ftpPassword, int ftpPort, String ftpPath, String localPath,

    String fileName) throws JSchException {

    Session session = null;

    Channel channel = null;

        JSch jsch = new JSch();  
        session = jsch.getSession(ftpUserName, ftpHost, ftpPort);  
        session.setPassword(ftpPassword);  
        session.setTimeout(100000);  
        Properties config = new Properties();  
        config.put("StrictHostKeyChecking", "no");  
        session.setConfig(config);  
        session.connect();  
    
        channel = session.openChannel("sftp");  
        channel.connect();  
        ChannelSftp chSftp = (ChannelSftp) channel;  
    
        String ftpFilePath = ftpPath + "/" + fileName;  
        String localFilePath = localPath + File.separatorChar + fileName;  
    
        try {  
            chSftp.get(ftpFilePath, localPath);  
        } catch (Exception e) {  
            e.printStackTrace();  
            logger.info("download error.");  
        } finally {  
            chSftp.quit();  
            channel.disconnect();  
            session.disconnect();  
        }  
    
    }  
    

    }

    参考以上代码 使用
    jsch-0.1.54.jar 可以成功

    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 maixpy训练模型,模型训练好了以后,开发板通电会报错,不知道是什么问题
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容