问题
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:
- One thread will open channel on the session to check if a file exists
- 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