添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

My file transfer to SFTP server is failing with exception: java.io.IOException: inputstream is closed

  • My code has been working for the last 1 year or so, without any issues.
  • Nor I did any code change.
  • This has been happening since last three days.
  • I tried to check if there was any changes to the Library in the last few days and there have been none, also I'm using the latest one : jsch-0.1.54.jar

    Here is my code:

        public void sendVsbFile(String fileName, MyObject c) {
        File f = new File(fileName);
        if (f.exists()) {
            String SFTPHOST = c.SFTPURL;
            int SFTPPORT = Integer.parseInt(c.SFTPPORT);
            String SFTPUSER = c.SFTPUserName;
            String SFTPPASS = c.SFTPPassword;
            String SFTPWORKINGDIR = c.FTPFolderLocation;
            Session session;
            Channel channel;
            ChannelSftp channelSftp;
            try {
                JSch jsch = new JSch();
                session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
                session.setPassword(SFTPPASS);
                java.util.Properties config = new java.util.Properties();
                config.put("StrictHostKeyChecking", "no");
                config.put("TCPKeepAlive", "yes");
                session.setConfig(config);
                session.setServerAliveInterval(120 * 1000);
                session.setServerAliveCountMax(1000);
                session.setTimeout(timeout);
                session.connect();
                System.out.println("Host connected.");
                channel = session.openChannel("sftp");
                channelSftp = (ChannelSftp) channel;
                channelSftp.connect();
                System.out.println("sftp channel opened and connected.");
                channelSftp.cd(SFTPWORKINGDIR);
                channelSftp.cd(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyLocalAndroidPath/");
                String suffix = ".filepart";
                Log.d(TAG, "file name = " + f.getName());
                String tempFileName = f.getName() + suffix;
                channelSftp.put(new FileInputStream(f), tempFileName, ChannelSftp.RESUME);
                String newFileName = tempFileName.substring(0, tempFileName.length() - suffix.length());
                channelSftp.rename(tempFileName, newFileName);
                System.out.println("File transferred successfully to host.");
            } catch (JSchException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (SftpException e) {
                e.printStackTrace();
    

    Many developers have posted this kind of issue, but there's no concrete solution provided. Please if anyone has ever faced this issue before, do help. Thanks.

    Here is the Stack Trace:

    java.io.IOException: inputstream is closed
        at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:697)
        at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:475)
        at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:365)
        at myMethod(MyClass.java:933)
        at myMethod.run(MyClass.java:804)
        at java.lang.Thread.run(Thread.java:818)
    Caused by: java.io.IOException: inputstream is closed
        at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2911)
        at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2935)
        at com.jcraft.jsch.ChannelSftp.checkStatus(ChannelSftp.java:2473)
        at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:686)
        ... 5 more
                    Show us exception callstack. Show us references to the "Many developers have posted this kind of issue".
    – Martin Prikryl
                    Oct 6, 2017 at 15:55
                    Hey Martin, I have edited my question with the exception stacktrace. For similar question posted, please check the below links : stackoverflow.com/questions/33405888/… & stackoverflow.com/questions/8968611/…
    – Mukesh Sharma
                    Oct 9, 2017 at 6:12
                    No idea. Where would I find the JSch Logs? Do I need to implement the JSch Logger for that?
    – Mukesh Sharma
                    Oct 9, 2017 at 9:00
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.