--- jsch-0.1.48/src/main/java/com/jcraft/jsch/ChannelSftp.java 2012-04-20 02:05:02.596874522 +0000 +++ jsch-0.1.49/src/main/java/com/jcraft/jsch/ChannelSftp.java 2012-09-25 03:55:20.344465826 +0000 @@ -1001,7 +1007,16 @@ length=header.length; type=header.type; - RequestQueue.Request rr = rq.get(header.rid); + RequestQueue.Request rr = null; + try{ + rr = rq.get(header.rid); + } + catch(RequestQueue.OutOfOrderException e){ + request_offset = e.offset; + skip(header.length); + rq.cancel(header, buf); + continue; + } if(type==SSH_FXP_STATUS){ fill(buf, length); @@ -1093,6 +1108,12 @@ private class RequestQueue { + class OutOfOrderException extends Exception { + long offset; + OutOfOrderException(long offset){ + this.offset=offset; + } + } class Request { int id; long offset; @@ -1123,13 +1144,20 @@ count++; } - Request get(int id){ + Request get(int id) throws OutOfOrderException{ count -= 1; int i=head; head++; if(head==rrq.length) head=0; - if(rrq[i].id!=id){ - System.err.println("The request is not in order."); + if(rrq[i].id != id){ + long offset = getOffset(); + for(int j=0; jrrq[i].offset) + result=rrq[i].offset; + } + + return result; + } } public InputStream get(String src) throws SftpException{ @@ -1284,7 +1331,16 @@ int type=header.type; int id=header.rid; - RequestQueue.Request rr = rq.get(header.rid); + RequestQueue.Request rr = null; + try{ + rr = rq.get(header.rid); + } + catch(RequestQueue.OutOfOrderException e){ + request_offset = e.offset; + skip(header.length); + rq.cancel(header, buf); + return 0; + } if(type!=SSH_FXP_STATUS && type!=SSH_FXP_DATA){ throw new IOException("error");