Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.IOException - End of IO Stream Read

Tags:

java

sftp

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();
}
like image 891
bouncingHippo Avatar asked Mar 28 '13 03:03

bouncingHippo


People also ask

What is IOException in Java?

java.io.IOException is an exception which programmers use in the code to throw a failure in Input & Output operations. It is a checked exception. The programmer needs to subclass the IOException and should throw the IOException subclass based on the context. 5. UML diagram

What is the EOF exception in a datastream?

This exception indicates the the end of file (EOF), or the end of stream has been reached unexpectedly. Also, this exception is mainly used by DataInputStreams, in order to signal the end of stream.

What is eofexception class in Java?

The EOFException class extends the IOException class, which is the general class of exceptions produced by failed, or interrupted I/O operations. Moreover, it implements the Serializable interface.


1 Answers

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.

like image 158
mike g Avatar answered Oct 04 '22 13:10

mike g