2013-03-28 145 views
7

代码似乎在session.connect中断。java.io.IOException - IO流结束读取

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

堆栈跟踪

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) 

代码

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

有与旧版本Jsch(如0.1.52)和OpenSSH的最新版本的互操作性问题(例如, OpenSSH_7.2p2)。升级到Jsch 0.1.54后,问题就消失了。

相关问题