Jsch sftp channel state impact by previous channel state of the same session?

馋奶兔 提交于 2019-12-25 06:32:43

问题


In my code I am trying to keep the Jsch session active cause I expect many interactions with the server will happen. And the logic is:

  1. One thread will open channel on the session to check if a file exists
  2. Another thread try to open channel on the same session to send a file to the server

However I found if #1 give me a "file not found", #2 will fail with the same exception at here:

      Header header=new Header();
      header=header(buf, header);
      int length=header.length;
      int type=header.type;

      fill(buf, length);

      if(type!=SSH_FXP_STATUS && type!=SSH_FXP_HANDLE){
    throw new SftpException(SSH_FX_FAILURE, "invalid type="+type);
      }
      if(type==SSH_FXP_STATUS){
        int i=buf.getInt();
>>>>    throwStatusError(buf, i); 
      }
      byte[] handle=buf.getString();         // handle
      byte[] data=null;

So the question is why the new channel got the same error with previous channel even before I put a single byte to the channel?


回答1:


Okay. So the issue is caused I've use the session to get an non-existing file before and the input stream returned by the get operation is not closed. That triggers all following operation on the same session throw out SftpException with id == 2, i.e. file not found



来源:https://stackoverflow.com/questions/23692643/jsch-sftp-channel-state-impact-by-previous-channel-state-of-the-same-session

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