java.io.IOException - End of IO Stream Read

大兔子大兔子 提交于 2020-01-02 02:39:06

问题


Code seems to break at session.connect.

com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read

Stacktrace

com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read
    at com.jcraft.jsch.Session.connect(Session.java:534)
    at com.jcraft.jsch.Session.connect(Session.java:162)
    at session.connect in uploadFile(ftpService.java:280)

Code

try {
    JSch jsch = new JSch();
    Session session = null;
    session = jsch.getSession(ftpUserName, ftpServer, 22);
    session.setClientVersion("StrictHostKeyChecking");
    //session.setConfig("StrictHostKeyChecking", "no");
    session.setPassword(ftpPassword);
    session.connect();

    Channel channel = session.openChannel("sftp");
    channel.connect();
    ChannelSftp sftpChannel = (ChannelSftp) channel;
    //sftpChannel.get("remotefile.txt", "localfile.txt");
    String path="C:\\srcFolder";
    String remotePath="C:\\destFolder";
    try {
        sftpChannel.put(new FileInputStream(new File(path)), remotePath  );
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        Logger.error(e);
        e.printStackTrace();
    }
    final Vector files = sftpChannel.ls(".");
    for (Object obj : files) {
        System.out.println("f:"+obj);
    }
    sftpChannel.exit();
    session.disconnect();
} catch (Exception e) {
    e.printStackTrace();
}

回答1:


There was an interoperability problem with older versions of Jsch (e.g. 0.1.52) and recent versions of openssh (e.g OpenSSH_7.2p2). The problem went away for me after upgrading to Jsch 0.1.54.



来源:https://stackoverflow.com/questions/15673977/java-io-ioexception-end-of-io-stream-read

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!