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

1

0

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?

Seay answered 16/5, 2014 at 4:27 Comment(0)
S
0

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

Seay answered 19/5, 2014 at 2:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.