Influence of Jsch sftp channel state on previous channel state of the same session?

In my code, I am trying to keep the Jsch session active, I expect a lot of server interactions to occur. And the logic is this:

  • One thread will open a pipe in session to check if the file exists
  • Another thread is trying to open a channel in the same session to send a file to the server

However, I found that if # 1 gives me "file not found", # 2 will work with the same exception:

      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 did the new channel get the same error with the previous channel even before I put one byte into the channel?

0


source to share


1 answer


Good. So the problem is because I am using the session to get a non-existent file before, and the input stream returned by the get operation is not being closed. This leads to the fact that all subsequent operations in one session throw SftpException with id == 2, that is, the file was not found.



0


source







All Articles