public Stream get(String src, SftpProgressMonitor monitor, int mode) { if(mode==RESUME) { throw new SftpException(SSH_FX_FAILURE, "faile to resume from "+src); } if(!src.StartsWith("/")){ src=cwd+"/"+src; } try { ArrayList v=glob_remote(src); if(v.Count!=1) { throw new SftpException(SSH_FX_FAILURE, v.ToString()); } src=(String)(v[0]); SftpATTRS attr=stat(src); if(monitor!=null) { monitor.init(SftpProgressMonitor.GET, src, "??", attr.getSize()); } sendOPENR(Util.getBytes(src)); buf.rewind(); int i=io.ins.Read(buf.buffer, 0, buf.buffer.Length); int length=buf.getInt(); int type=buf.getByte(); if(type!=SSH_FXP_STATUS && type!=SSH_FXP_HANDLE) { throw new SftpException(SSH_FX_FAILURE, ""); } if(type==SSH_FXP_STATUS) { buf.getInt(); i=buf.getInt(); throwStatusError(buf, i); } buf.getInt(); byte[] handle=buf.getString(); // filename long[] _offset=new long[1]; //_offset[0]=0; int[] _server_version=new int[1]; _server_version[0]=server_version; InputStreamGet ins=new InputStreamGet(this, handle, _offset, _server_version, monitor); return ins; } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
public InputStream get(String src, SftpProgressMonitor monitor, int mode) { //throws SftpException{ if(mode==RESUME) { throw new SftpException(SSH_FX_FAILURE, "faile to resume from "+src); } src=remoteAbsolutePath(src); try { Vector v=glob_remote(src); if(v.size()!=1) { throw new SftpException(SSH_FX_FAILURE, v.toString()); } src=(String)(v.elementAt(0)); SftpATTRS attr=_stat(src); if(monitor!=null) { monitor.init(SftpProgressMonitor.GET, src, "??", attr.getSize()); } 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) { throw new SftpException(SSH_FX_FAILURE, ""); } if(type==SSH_FXP_STATUS) { int i=buf.getInt(); throwStatusError(buf, i); } byte[] handle=buf.getString(); // filename java.io.InputStream ins=new InputStreamGet(this, handle, monitor); // long offset=0; // bool closed=false; // int rest_length=0; // byte[] _data=new byte[1]; // public int read() { //throws java.io.IOException{ // int i=read(_data, 0, 1); // if (i==-1) { return -1; } // else { // return _data[0]&0xff; // } // } // public int read(byte[] d) { //throws java.io.IOException{ // return read(d, 0, d.Length); // } // public int read(byte[] d, int s, int len) { //throws java.io.IOException{ // if(d==null){throw new NullPointerException();} // if(s<0 || len <0 || s+len>d.Length){ // throw new IndexOutOfBoundsException(); // } // if(len==0){ return 0; } // if(rest_length>0){ // int foo=rest_length; // if(foo>len) foo=len; // int i=io.ins.read(d, s, foo); // if(i<0){ // throw new IOException("error"); // } // rest_length-=i; // return i; // } // if(buf.buffer.Length-13<len){ // len=buf.buffer.Length-13; // } // if(server_version==0 && len>1024){ // len=1024; // } // try{sendREAD(handle, offset, len);} // catch(Exception e){ throw new IOException("error"); } // buf.rewind(); // int i=io.ins.read(buf.buffer, 0, 13); // 4 + 1 + 4 + 4 // if(i!=13){ // throw new IOException("error"); // } // rest_length=buf.getInt(); // int type=buf.getByte(); // rest_length--; // buf.getInt(); // rest_length-=4; // if(type!=SSH_FXP_STATUS && type!=SSH_FXP_DATA){ // throw new IOException("error"); // } // if(type==SSH_FXP_STATUS){ // i=buf.getInt(); // rest_length-=4; // io.ins.read(buf.buffer, 13, rest_length); // rest_length=0; // if(i==SSH_FX_EOF){ // close(); // return -1; // } // //throwStatusError(buf, i); // throw new IOException("error"); // } // i=buf.getInt(); // rest_length-=4; // offset+=rest_length; // int foo=i; // if(foo>0){ // int bar=rest_length; // if(bar>len){ // bar=len; // } // i=io.ins.read(d, s, bar); // if(i<0){ // return -1; // } // rest_length-=i; // if(monitor!=null){ // if(!monitor.count(i)){ // return -1; // } // } // return i; // } // return 0; // ?? // } // public void close() { //throws IOException{ // if(closed)return; // closed=true; // /* // while(rest_length>0){ // int foo=rest_length; // if(foo>buf.buffer.Length){ // foo=buf.buffer.Length; // } // io.ins.read(buf.buffer, 0, foo); // rest_length-=foo; // } // */ // if(monitor!=null)monitor.end(); // try{_sendCLOSE(handle);} // catch(Exception e){throw new IOException("error");} // } //}; return ins; } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
public InputStream get(String remoteAbsolutePath, SftpProgressMonitor monitor, int mode) { if (mode == RESUME) { throw new SftpException(SSH_FX_FAILURE, "faile to resume from " + remoteAbsolutePath); } remoteAbsolutePath = this.remoteAbsolutePath(remoteAbsolutePath); try { ArrayList v = glob_remote(remoteAbsolutePath); if (v.Count != 1) { throw new SftpException(SSH_FX_FAILURE, v.ToString()); } remoteAbsolutePath = (String)(v[0]); SftpATTRS attr = GetPathAttributes(remoteAbsolutePath); if (monitor != null) { monitor.init(SftpProgressMonitor.GET, remoteAbsolutePath, "??", attr.getSize()); } sendOPENR(remoteAbsolutePath.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, ""); } if (type == SSH_FXP_STATUS) { int i = buf.getInt(); throwStatusError(buf, i); } byte[] handle = buf.getString(); // filename InputStream ins = new InputStreamGet(this, handle, monitor); return ins; } catch (Exception e) { if (e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }