public override void Close() { if (!init) { try { int _ackcount = sftp.seq - startid; while (_ackcount > ackcount) { if (!sftp.checkStatus(null, header)) { break; } ackcount++; } } catch (SftpException e) { throw new IOException(e.ToString()); } } if (monitor != null) { monitor.end(); } try{ sftp._sendCLOSE(handle, header); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e.ToString()); } }
public override void Close() { if (closed) { return; } closed = true; if (monitor != null) { monitor.end(); } try { sftp._sendCLOSE(handle, header); } catch (Exception) { throw new System.IO.IOException("error"); } }
private void _put(InputStream src, String dst, SftpProgressMonitor monitor, int mode) { try { long skip=0; if(mode==RESUME || mode==APPEND) { try { SftpATTRS attr=_stat(dst); skip=attr.getSize(); } catch(Exception eee) { //System.err.println(eee); } } if(mode==RESUME && skip>0) { long skipped=src.skip(skip); if(skipped<skip) { throw new SftpException(SSH_FX_FAILURE, "failed to resume for "+dst); } } if(mode==OVERWRITE){ sendOPENW(dst.getBytes()); } else{ sendOPENA(dst.getBytes()); } Header _header=new Header(); _header=header(buf, _header); int length=_header.length; int type=_header.type; buf.rewind(); fill(buf.buffer, 0, 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(); // filename byte[] data=null; bool dontcopy=true; if(!dontcopy) { data=new byte[buf.buffer.Length -(5+13+21+handle.Length +32 +20 // padding and mac ) ]; } long offset=0; if(mode==RESUME || mode==APPEND) { offset+=skip; } int startid=seq; int _ackid=seq; int ackcount=0; while(true) { int nread=0; int s=0; int datalen=0; int count=0; if(!dontcopy) { datalen=data.Length-s; } else { data=buf.buffer; s=5+13+21+handle.Length; datalen=buf.buffer.Length -s -32 -20; // padding and mac } do { nread=src.read(data, s, datalen); if(nread>0) { s+=nread; datalen-=nread; count+=nread; } } while(datalen>0 && nread>0); if(count<=0)break; int _i=count; while(_i>0) { _i-=sendWRITE(handle, offset, data, 0, _i); if((seq-1)==startid || io.ins.available()>=1024) { while(io.ins.available()>0) { if(checkStatus(ackid, _header)) { _ackid=ackid[0]; if(startid>_ackid || _ackid>seq-1) { if(_ackid==seq) { java.System.err.println("ack error: startid="+startid+" seq="+seq+" _ackid="+_ackid); } else { //throw new SftpException(SSH_FX_FAILURE, "ack error:"); throw new SftpException(SSH_FX_FAILURE, "ack error: startid="+startid+" seq="+seq+" _ackid="+_ackid); } } ackcount++; } else { break; } } } } offset+=count; if(monitor!=null && !monitor.count(count)) { break; } } int _ackcount=seq-startid; while(_ackcount>ackcount) { if(!checkStatus(null, _header)) { break; } ackcount++; } if(monitor!=null)monitor.end(); _sendCLOSE(handle, _header); //System.err.println("start end "+startid+" "+endid); } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, e.toString()); } }
///tamir: updated to jcsh-0.1.30 private void _get(String src, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip) { //throws SftpException{ //System.out.println("_get: "+src+", "+dst); //try //{ sendOPENR(src.getBytes()); Header _header=new Header(); _header=header(buf, _header); int length=_header.length; int type=_header.type; buf.rewind(); fill(buf.buffer, 0, length); if(type!=SSH_FXP_STATUS && type!=SSH_FXP_HANDLE) { //System.Console.WriteLine("Type is "+type); throw new SftpException(SSH_FX_FAILURE, "Type is "+type); } if(type==SSH_FXP_STATUS) { int i=buf.getInt(); throwStatusError(buf, i); } byte[] handle=buf.getString(); // filename long offset=0; if(mode==RESUME) { offset+=skip; } int request_len=0; loop: while(true) { request_len=buf.buffer.Length-13; if(server_version==0){ request_len=1024; } sendREAD(handle, offset, request_len); _header=header(buf, _header); length=_header.length; type=_header.type; int i; if(type==SSH_FXP_STATUS) { buf.rewind(); fill(buf.buffer, 0, length); i=buf.getInt(); if(i==SSH_FX_EOF) { goto BREAK; } throwStatusError(buf, i); } if(type!=SSH_FXP_DATA) { goto BREAK; } buf.rewind(); fill(buf.buffer, 0, 4); length-=4; i=buf.getInt(); // length of data int foo=i; while(foo>0) { int bar=foo; if(bar>buf.buffer.Length) { bar=buf.buffer.Length; } i=io.ins.read(buf.buffer, 0, bar); if(i<0) { goto BREAK; } int data_len=i; dst.write(buf.buffer, 0, data_len); offset+=data_len; foo-=data_len; if(monitor!=null) { if(!monitor.count(data_len)) { while(foo>0) { i=io.ins.read(buf.buffer, 0, (buf.buffer.Length<foo?buf.buffer.Length:foo)); if(i<=0) break; foo-=i; } goto BREAK; } } } //System.out.println("length: "+length); // length should be 0 } BREAK: dst.flush(); if(monitor!=null)monitor.end(); _sendCLOSE(handle, _header); //} //catch(Exception e) //{ // //System.Console.WriteLine(e); // if(e is SftpException) throw (SftpException)e; // throw new SftpException(SSH_FX_FAILURE, ""); //} }