7

コードは で壊れているよう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();
}
4

1 に答える 1

1

古いバージョンの Jsch (例: 0.1.52) と最近のバージョンの openssh (例: OpenSSH_7.2p2) には相互運用性の問題がありました。Jsch 0.1.54 にアップグレードすると、この問題は解消されました。

于 2016-11-24T17:12:13.483 に答える