Ejemplo n.º 1
0
		public void get(String src, String dst,
			SftpProgressMonitor monitor, int mode)
		{
			//throws SftpException{
			src=remoteAbsolutePath(src);
			dst=localAbsolutePath(dst);
			try
			{
				Vector v=glob_remote(src);
				int vsize=v.size();
				if(vsize==0)
				{
					throw new SftpException(SSH_FX_NO_SUCH_FILE, "No such file");
				}

				File dstFile=new File(dst);
				bool isDstDir=dstFile.isDirectory();
				StringBuffer dstsb=null;
				if(isDstDir)
				{
					if(!dst.endsWith(file_separator))
					{
						dst+=file_separator;
					}
					dstsb=new StringBuffer(dst);
				}
				else if(vsize>1)
				{
					throw new SftpException(SSH_FX_FAILURE, "Copying multiple files, but destination is missing or a file.");
				}

				for(int j=0; j<vsize; j++)
				{
					String _src=(String)(v.elementAt(j));

					SftpATTRS attr=_stat(_src);
					if(attr.isDir())
					{
						throw new SftpException(SSH_FX_FAILURE, "not supported to get directory "+_src);
					} 

					String _dst=null;
					if(isDstDir)
					{
						int i=_src.lastIndexOf('/');
						if(i==-1) dstsb.append(_src);
						else dstsb.append(_src.substring(i + 1));
						_dst=dstsb.toString();
						dstsb.delete(dst.length(), _dst.length());
					}
					else
					{
						_dst=dst;
					}

					if(mode==RESUME)
					{
						long size_of_src=attr.getSize();
						long size_of_dst=new File(_dst).length();
						if(size_of_dst>size_of_src)
						{
							throw new SftpException(SSH_FX_FAILURE, "failed to resume for "+_dst);
						}
						if(size_of_dst==size_of_src)
						{
							return;
						}
					}

					if(monitor!=null)
					{
						monitor.init(SftpProgressMonitor.GET, _src, _dst, attr.getSize());
						if(mode==RESUME)
						{
							monitor.count(new File(_dst).length());
						}
					}
					FileOutputStream fos=null;
					if(mode==OVERWRITE)
					{
						fos=new FileOutputStream(_dst);
					}
					else
					{
						fos=new FileOutputStream(_dst, true); // append
					}

					//System.err.println("_get: "+_src+", "+_dst);
					_get(_src, fos, monitor, mode, new File(_dst).length());
					fos.close();
				}
			}
			catch(Exception e)
			{
				if(e is SftpException) throw (SftpException)e;
				throw new SftpException(SSH_FX_FAILURE, "");
			}
		}
Ejemplo n.º 2
0
		public void get(String src, OutputStream dst,
			SftpProgressMonitor monitor, int mode, long skip)
		{
			//throws SftpException{
			//try
			//{
				src=remoteAbsolutePath(src);
				Vector v=glob_remote(src);
				if(v.size()!=1)
				{
					throw new SftpException(SSH_FX_FAILURE, v.toString());
				}
				src=(String)(v.elementAt(0));

				if(monitor!=null)
				{
					SftpATTRS attr=_stat(src);
					monitor.init(SftpProgressMonitor.GET, src, "??", attr.getSize());
					if(mode==RESUME)
					{
						monitor.count(skip);
					}
				}
				_get(src, dst, monitor, mode, skip);
			//}
			//catch(Exception e)
			//{
			//	if(e is SftpException) throw (SftpException)e;
			//	throw new SftpException(SSH_FX_FAILURE, "");
			//}
		}
Ejemplo n.º 3
0
		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, "");
			}
		}
Ejemplo n.º 4
0
		public void put(String src, String dst,
			SftpProgressMonitor monitor, int mode)
		{
			//throws SftpException{
			src=localAbsolutePath(src);
			dst=remoteAbsolutePath(dst);

			//System.err.println("src: "+src+", "+dst);
			try
			{
				Vector v=glob_remote(dst);
				int vsize=v.size();
				if(vsize!=1)
				{
					if(vsize==0)
					{
						if(isPattern(dst))
							throw new SftpException(SSH_FX_FAILURE, dst);
						else
							dst=Util.unquote(dst);
					}
					throw new SftpException(SSH_FX_FAILURE, v.toString());
				}
				else
				{
					dst=(String)(v.elementAt(0));
				}

				//System.err.println("dst: "+dst);

				bool _isRemoteDir=isRemoteDir(dst);

				v=glob_local(src);
				//System.err.println("glob_local: "+v+" dst="+dst);
				vsize=v.size();

				StringBuffer dstsb=null;
				if(_isRemoteDir)
				{
					if(!dst.endsWith("/"))
					{
						dst+="/";
					}
					dstsb=new StringBuffer(dst);
				}
				else if(vsize>1)
				{
					throw new SftpException(SSH_FX_FAILURE, "Copying multiple files, but destination is missing or a file.");
				}

				for(int j=0; j<vsize; j++)
				{
					String _src=(String)(v.elementAt(j));
					String _dst=null;
					if(_isRemoteDir)
					{
						int i=_src.lastIndexOf(file_separatorc);
						if(i==-1) dstsb.append(_src);
						else dstsb.append(_src.substring(i + 1));
						_dst=dstsb.toString();
						dstsb.delete(dst.length(), _dst.length());
					}
					else
					{
						_dst=dst;
					}
					//System.err.println("_dst "+_dst);

					long size_of_dst=0;
					if(mode==RESUME)
					{
						try
						{
							SftpATTRS attr=_stat(_dst);
							size_of_dst=attr.getSize();
						}
						catch(Exception eee)
						{
							//System.err.println(eee);
						}
						long size_of_src=new File(_src).length();
						if(size_of_src<size_of_dst)
						{
							throw new SftpException(SSH_FX_FAILURE, "failed to resume for "+_dst);
						}
						if(size_of_src==size_of_dst)
						{
							return;
						}
					}

					if(monitor!=null)
					{
						monitor.init(SftpProgressMonitor.PUT, _src, _dst,
						             (new File(_src)).length());
						if(mode==RESUME)
						{
							monitor.count(size_of_dst);
						}
					}
					FileInputStream fis=null;
					try
					{
						fis=new FileInputStream(_src);
						_put(fis, _dst, monitor, mode);
					}
					finally
					{
						if(fis!=null) 
						{
							//	    try{
							fis.close();
							//	    }catch(Exception ee){};
						}
					}
				}
			}
			catch(Exception e)
			{
				if(e is SftpException) throw (SftpException)e;
				throw new SftpException(SSH_FX_FAILURE, e.toString());
			}
		}
Ejemplo n.º 5
0
		public void get(String src, String dst,
			SftpProgressMonitor monitor, int mode)
		{
			//throws SftpException{
			src = RemoteAbsolutePath(src);
			dst = localAbsolutePath(dst);
			try
			{
				ArrayList v = glob_remote(src);
				int vsize = v.Count;
				if (vsize == 0)
				{
					throw new SftpException(SSH_FX_NO_SUCH_FILE, "No such file");
				}

				bool isDstDir = System.IO.Directory.Exists(dst);
				string dstsb = "";
				if (isDstDir)
				{
					if (!dst.EndsWith(file_separator))
					{
						dst += file_separator;
					}
					dstsb = (dst);
				}
				else if (vsize > 1)
				{
					throw new SftpException(SSH_FX_FAILURE, "Copying multiple files, but destination is missing or a file.");
				}

				for (int j = 0; j < vsize; j++)
				{
					String _src = (String)(v[j]);

					SftpATTRS attr = _stat(_src);
					if (attr.IsDirectory)
					{
						throw new SftpException(SSH_FX_FAILURE, "not supported to get directory " + _src);
					}

					String _dst = null;
					if (isDstDir)
					{
						int i = _src.LastIndexOf('/');
						if (i == -1) dstsb += (_src);
						else dstsb += (_src.Substring(i + 1));
						_dst = dstsb;
						dstsb = dstsb.Remove(dst.Length, _dst.Length);
					}
					else
					{
						_dst = dst;
					}

					if (mode == RESUME)
					{
						long size_of_src = attr.Size;
						long size_of_dst = new System.IO.FileInfo(_dst).Length;
						if (size_of_dst > size_of_src)
						{
							throw new SftpException(SSH_FX_FAILURE, "failed to resume for " + _dst);
						}
						if (size_of_dst == size_of_src)
						{
							return;
						}
					}

					if (monitor != null)
					{
						monitor.init(SftpProgressMonitor.GET, _src, _dst, attr.Size);
						if (mode == RESUME)
						{
							monitor.count(new System.IO.FileInfo(_dst).Length);
						}
					}
					FileOutputStream fos = null;
					if (mode == OVERWRITE)
					{
						fos = new FileOutputStream(_dst);
					}
					else
					{
						fos = new FileOutputStream(_dst, true); // append
					}

					//System.err.println("_get: "+_src+", "+_dst);
					_get(_src, fos, monitor, mode, new System.IO.FileInfo(_dst).Length);
					fos.close();
				}
			}
			catch (Exception e)
			{
				if (e is SftpException) throw (SftpException)e;
				throw new SftpException(SSH_FX_FAILURE, "");
			}
		}
Ejemplo n.º 6
0
		public void get(String src, OutputStream dst,
			SftpProgressMonitor monitor, int mode, long skip)
		{
			//throws SftpException{
			try
			{
				src = RemoteAbsolutePath(src);
				ArrayList v = glob_remote(src);
				if (v.Count != 1)
				{
					throw new SftpException(SSH_FX_FAILURE, v.ToString());
				}
				src = (String)(v[0]);

				if (monitor != null)
				{
					SftpATTRS attr = _stat(src);
					monitor.init(SftpProgressMonitor.GET, src, "??", attr.Size);
					if (mode == RESUME)
					{
						monitor.count(skip);
					}
				}
				_get(src, dst, monitor, mode, skip);
			}
			catch (Exception e)
			{
				if (e is SftpException) throw (SftpException)e;
				throw new SftpException(SSH_FX_FAILURE, "");
			}
		}
Ejemplo n.º 7
0
		public void put(String src, String dst,
			SftpProgressMonitor monitor, int mode)
		{
			//throws SftpException{
			src = localAbsolutePath(src);
			dst = RemoteAbsolutePath(dst);

			//System.err.println("src: "+src+", "+dst);
			try
			{
				ArrayList v = glob_remote(dst);
				int vsize = v.Count;
				if (vsize != 1)
				{
					if (vsize == 0)
					{
						if (IsPattern(dst))
							throw new SftpException(SSH_FX_FAILURE, dst);
						else
							dst = Util.unquote(dst);
					}
					throw new SftpException(SSH_FX_FAILURE, v.ToString());
				}
				else
				{
					dst = (String)(v[0]);
				}

				//System.err.println("dst: "+dst);

				bool _isRemoteDir = isRemoteDir(dst);

				v = glob_local(src);
				//System.err.println("glob_local: "+v+" dst="+dst);
				vsize = v.Count;

				string dstsb = "";
				if (_isRemoteDir)
				{
					if (!dst.EndsWith("/"))
					{
						dst += "/";
					}
					dstsb = (dst);
				}
				else if (vsize > 1)
				{
					throw new SftpException(SSH_FX_FAILURE, "Copying multiple files, but destination is missing or a file.");
				}

				for (int j = 0; j < vsize; j++)
				{
					String _src = (String)(v[j]);
					String _dst = null;
					if (_isRemoteDir)
					{
						int i = _src.LastIndexOf(file_separatorc);
						if (i == -1) dstsb += (_src);
						else dstsb += (_src.Substring(i + 1));
						_dst = dstsb;
						dstsb = dstsb.Remove(dst.Length, _dst.Length);
					}
					else
					{
						_dst = dst;
					}
					//System.err.println("_dst "+_dst);

					long size_of_dst = 0;
					if (mode == RESUME)
					{
						try
						{
							SftpATTRS attr = _stat(_dst);
							size_of_dst = attr.Size;
						}
						catch (Exception)
						{
							//System.err.println(eee);
						}

						long size_of_src = new System.IO.FileInfo(_src).Length;
						if (size_of_src < size_of_dst)
						{
							throw new SftpException(SSH_FX_FAILURE, "failed to resume for " + _dst);
						}
						if (size_of_src == size_of_dst)
						{
							return;
						}
					}

					if (monitor != null)
					{
						monitor.init(
							SftpProgressMonitor.PUT,
							_src,
							_dst,
							new System.IO.FileInfo(_src).Length
						);
						if (mode == RESUME)
						{
							monitor.count(size_of_dst);
						}
					}
					FileInputStream fis = null;
					try
					{
						fis = new FileInputStream(_src);
						_put(fis, _dst, monitor, mode);
					}
					finally
					{
						if (fis != null)
						{
							//	    try{
							fis.close();
							//	    }catch(Exception ee){};
						}
					}
				}
			}
			catch (Exception e)
			{
				if (e is SftpException) throw (SftpException)e;
				throw new SftpException(SSH_FX_FAILURE, e.ToString());
			}
		}
Ejemplo n.º 8
0
        public void put(String src, String dst, SftpProgressMonitor monitor, int mode)
        {
            src = localAbsolutePath(src);
            dst = remoteAbsolutePath(dst);

            try
            {
                ArrayList v = glob_remote(dst);
                int vsize = v.Count;
                if (vsize != 1)
                {
                    if (vsize == 0)
                    {
                        if (isPattern(dst))
                            throw new SftpException(SSH_FX_FAILURE, dst);
                        else
                            dst = Util.unquote(dst);
                    }
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }
                else
                {
                    dst = (String)(v[0]);
                }

                bool _isRemoteDir = isRemoteDir(dst);

                v = glob_local(src);
                vsize = v.Count;

                StringBuilder dstsb = null;
                if (_isRemoteDir)
                {
                    if (!dst.EndsWith("/"))
                    {
                        dst += "/";
                    }

                    dstsb = new StringBuilder(dst);
                }
                else if (vsize > 1)
                {
                    throw new SftpException(SSH_FX_FAILURE, "Copying multiple files, but destination is missing or a file.");
                }

                for (int j = 0; j < vsize; j++)
                {
                    String _src = (String)(v[j]);
                    String _dst = null;
                    if (_isRemoteDir)
                    {
                        int i = _src.LastIndexOf(file_separatorc);
                        if (i == -1) dstsb.Append(_src);
                        else dstsb.Append(_src.Substring(i + 1));
                        _dst = dstsb.ToString();
                        dstsb.Remove(dst.Length, _dst.Length);
                    }
                    else
                    {
                        _dst = dst;
                    }

                    long size_of_dst = 0;
                    if (mode == RESUME)
                    {
                        try
                        {
                            SftpATTRS attr = GetPathAttributes(_dst);
                            size_of_dst = attr.getSize();
                        }
                        catch (Exception) { }

                        long size_of_src = new File(_src).Length();
                        if (size_of_src < size_of_dst)
                        {
                            throw new SftpException(SSH_FX_FAILURE, "failed to resume for " + _dst);
                        }
                        if (size_of_src == size_of_dst)
                        {
                            return;
                        }
                    }

                    if (monitor != null)
                    {
                        monitor.init(SftpProgressMonitor.PUT, _src, _dst, (new File(_src)).Length());
                        if (mode == RESUME)
                        {
                            monitor.count(size_of_dst);
                        }
                    }
                    FileInputStream fis = null;
                    try
                    {
                        fis = new FileInputStream(_src);
                        _put(fis, _dst, monitor, mode);
                    }
                    finally
                    {
                        if (fis != null)
                        {
                            fis.close();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, e.Message);
            }
        }
Ejemplo n.º 9
0
        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, "");
            }
        }
Ejemplo n.º 10
0
        public void get(String remoteAbsolutePath, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip)
        {
            try
            {
                remoteAbsolutePath = this.remoteAbsolutePath(remoteAbsolutePath);
                ArrayList v = glob_remote(remoteAbsolutePath);

                if (v.Count != 1)
                {
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }

                remoteAbsolutePath = (String)(v[0]);

                if (monitor != null)
                {
                    SftpATTRS attr = GetPathAttributes(remoteAbsolutePath);
                    monitor.init(SftpProgressMonitor.GET, remoteAbsolutePath, "??", attr.getSize());
                    if (mode == RESUME)
                    {
                        monitor.count(skip);
                    }
                }

                _get(remoteAbsolutePath, dst, monitor, mode, skip);
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
Ejemplo n.º 11
0
        public void get(String remoteAbsolutePath, String localAbsolutePath, SftpProgressMonitor monitor, int mode)
        {
            remoteAbsolutePath = this.remoteAbsolutePath(remoteAbsolutePath);
            localAbsolutePath = this.localAbsolutePath(localAbsolutePath);

            try
            {
                ArrayList files = glob_remote(remoteAbsolutePath);

                if (files.Count == 0)
                {
                    throw new SftpException(SSH_FX_NO_SUCH_FILE, "No such file");
                }

                bool copyingToDirectory = new File(localAbsolutePath).isDirectory();

                // if we're not copying to a directory but we're copying multiple files, there's a problem
                if (false == copyingToDirectory && files.Count > 1)
                {
                    throw new SftpException(SSH_FX_FAILURE, "Copying multiple files, but destination is missing or is a file.");
                }

                // if the given local path doesn't end with a '\' or other file separator, add one
                if (!localAbsolutePath.EndsWith(file_separator))
                {
                    localAbsolutePath += file_separator;
                }

                for (int j = 0; j < files.Count; j++)
                {
                    String sourceFile = (String)(files[j]);

                    SftpATTRS attr = GetPathAttributes(sourceFile);

                    // get information on the current file
                    if (attr.isDir())
                    {
                        // right now it's not able to get a directory
                        throw new SftpException(SSH_FX_FAILURE, "not supported to get directory " + sourceFile);
                    }

                    String destinationPath = null;

                    if (copyingToDirectory)
                    {
                        StringBuilder destinationSb = new StringBuilder(localAbsolutePath);

                        // find the last file separator character
                        int i = sourceFile.LastIndexOf(file_separatorc);

                        // basically we're appending just the filename
                        if (i == -1)
                            destinationSb.Append(sourceFile);
                        else
                            destinationSb.Append(sourceFile.Substring(i + 1));

                        destinationPath = destinationSb.ToString();
                    }
                    else
                    {
                        destinationPath = localAbsolutePath;
                    }

                    if (mode == RESUME)
                    {
                        long sizeOfSourceFile = attr.getSize();

                        long sizeOfDestinationFile = new File(destinationPath).Length();

                        // this means we already copied more data than is available. fail
                        if (sizeOfDestinationFile > sizeOfSourceFile)
                        {
                            throw new SftpException(SSH_FX_FAILURE, "failed to resume for " + destinationPath);
                        }

                        // if the sizes are equal, we're gravy
                        if (sizeOfDestinationFile == sizeOfSourceFile)
                        {
                            return;
                        }
                    }

                    if (monitor != null)
                    {
                        monitor.init(SftpProgressMonitor.GET, sourceFile, destinationPath, attr.getSize());

                        if (mode == RESUME)
                        {
                            monitor.count(new File(destinationPath).Length());
                        }
                    }

                    // create the output stream, and append if it's in overwrite mode
                    FileOutputStream fileOutputStream = new FileOutputStream(destinationPath, mode == OVERWRITE);

                    _get(sourceFile, fileOutputStream, monitor, mode, new File(destinationPath).Length());

                    fileOutputStream.Close();
                }
            }
            catch (SftpException)
            {
                throw;
            }
            catch (Exception)
            {
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }