Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jsch throwing End of file Exception

Tags:

java

sftp

ftp

jsch

This happens on some files but not on others.

1: End of file
        at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
        at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2198)
        at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1294)
        at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1266)

The code is simple:

        jsch.addIdentity("privateKeyFromOdin", sftpPrivateKey, null, null);
        session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.connect();
        Channel channel = session.openChannel("sftp");
        channel.connect();
        channelSftp = (ChannelSftp) channel;

        Vector<ChannelSftp.LsEntry> ls = channelSftp.ls(".");
        for (ChannelSftp.LsEntry entry : ls) {
                String fileName = entry.getFilename();
                encryptedStream = channelSftp.get(fileName);//Exception thrown here
        }

What's even more odd is that this used to work well. But I don't know what changed.

like image 850
Kam Avatar asked Oct 28 '25 14:10

Kam


1 Answers

I had similar issue, I was not closing inputStream returned by each "channelSftp.get(fileName)" call, try closing inputStream

like image 93
vivek pandey Avatar answered Oct 31 '25 03:10

vivek pandey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!