[英]java.io.IOException - End of IO Stream Read
代碼似乎在session.connect
中斷。
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();
}
舊版本的Jsch(例如0.1.52)和最新版本的openssh(例如OpenSSH_7.2p2)存在互操作性問題。 升級到Jsch 0.1.54之后,問題就消失了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.