inputstream is closed error while uploading zip file through jsch to sftp site

心不动则不痛 提交于 2019-12-20 06:32:23

问题


While uploading a zip file to SFTP, we are getting the below error. The same code is working fine for another application. We are using jsch-0.1.44.jar for SFTP connection.

java.io.IOException: inputstream is closed
        at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:571)
        at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:431)
        at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:398)
aused by: java.io.IOException: inputstream is closed
        at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2326)
        at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2350)
        at com.jcraft.jsch.ChannelSftp.checkStatus(ChannelSftp.java:1923)
        at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:559)
        ... 6 more

回答1:


I searched stackoverflow and many other sources in internet to get an answer. There were two reasons I found which was not the cause for my specific issue.

1) This exception usually means the connection was closed abruptly. I would look at the logs on the server to see if there was an error. 2)The root cause of this error was that in the code, remote path was being opened twice. So, even if, no channel is actually closed, but, when the remote path is tried to open 2nd time, the existing path/channel is also closed or something and this exception is raised.

After doing some POC, whatever changes we made to code did not have any impact. One of the thing which was looked at was passing inputstream object as a parameter to a method where actually put method of channelsftp is being called.

this.channelSftp.put(inputstream, strFileName );

Instead of passing inputstream from another method, code was written to form inputstream inside the method where this put is being called. This does not have any impact.

Tried uploading a file to sftp site through code. Same error was being thrown.

Later what we found was that there was no code issue. Even a manual upload was failing. This indicated us to dig further about this SFTP engagement details and found that the FILENAME format we are using is not what SFTP has configured. When we matched the filename format, the issue was resolved.




回答2:


I've recently encountered an issue similar to this, in my case it was a an issue when logging on to the remote machine using JSch.

When trying to manually connect to the machine I found that the password had expired and was prompting for a new one on login. It was able to connect and authenticate however once connected it was unable to get any further. This explained why it was an inputstream failure and not an authentication failure.

I know this is an old question but to anyone else in the same position trawling the web for an answer it might just be a simple solution like this.



来源:https://stackoverflow.com/questions/33405888/inputstream-is-closed-error-while-uploading-zip-file-through-jsch-to-sftp-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!