java.io.IOException - IO 流读取结束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15673977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 20:27:29 来源:igfitidea点击:
java.io.IOException - End of IO Stream Read
提问by bouncingHippo
Code seems to break at session.connect
.
代码似乎在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();
}
回答by mike g
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.
旧版本的 Jsch(例如 0.1.52)和最新版本的 openssh(例如 OpenSSH_7.2p2)存在互操作性问题。升级到 Jsch 0.1.54 后,问题就消失了。