Package org.vngx.jsch.exception

Examples of org.vngx.jsch.exception.SftpException


      }

      sendOPENR(srcb);
      readResponse();
      if( _header.type != SSH_FXP_HANDLE ) {
        throw new SftpException(SSH_FX_FAILURE, "Invalid FXP response: "+_header.type);
      }
      byte[] handle = _buffer.getString();         // handle

      return new GetInputStream(skip, handle, monitor);
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to get src: "+src, e);
    }
  }
View Full Code Here


      }

      sendOPENDIR(Util.str2byte(dir, _fileEncoding));
      readResponse();
      if( _header.type != SSH_FXP_HANDLE ) {
        throw new SftpException(SSH_FX_FAILURE, "Invalid FXP response: "+_header.type);
      }

      byte[] handle = _buffer.getString();         // handle
      List<LsEntry> lsEntries = new ArrayList<LsEntry>();
      while( true ) {
        sendREADDIR(handle);
        readHeader();
        if( _header.type != SSH_FXP_STATUS && _header.type != SSH_FXP_NAME ) {
          throw new SftpException(SSH_FX_FAILURE, "Invalid FXP response: "+_header.type);
        } else if( _header.type == SSH_FXP_STATUS ) {
          fill(_buffer, _header.length);
          int i = _buffer.getInt();
          if( i == SSH_FX_EOF ) {
            break;
          }
          throwStatusError(_buffer, i);
        }

        _buffer.rewind();
        fill(_buffer.buffer, 0, 4);
        _header.length -= 4;
        int count = _buffer.getInt();
        _buffer.reset();

        while( count > 0 ) {
          if( _header.length > 0 ) {
            _buffer.shift();
            int j = (_buffer.buffer.length > (_buffer.index + _header.length)) ? _header.length : (_buffer.buffer.length - _buffer.index);
            int i = fill(_buffer.buffer, _buffer.index, j);
            _buffer.index += i;
            _header.length -= i;
          }
          byte[] bFilename = _buffer.getString();
          String sFilename = Util.byte2str(bFilename, _fileEncoding);
          byte[] bLongname = _serverVersion <= 3 ? _buffer.getString() : null;
          SftpATTRS attrs = SftpATTRS.getATTR(_buffer);

          boolean found = false;
          if( bPattern == null ) {
            found = true;
          } else if( !wildcardPattern ) {
            found = Arrays.equals(bPattern, bFilename);
          } else {
            found = Util.glob(bPattern, _utf8 ? bFilename : Util.str2byte(sFilename, UTF8));
          }

          if( found ) {
            // TODO: need to generate long name from attrs for sftp protocol 4(and later)
            String sLongname = bLongname == null ?
              (attrs.toString() + " " + sFilename) :
              Util.byte2str(bLongname, _fileEncoding);
            lsEntries.add(new LsEntry(sFilename, sLongname, attrs));
          }
          count--;
        }
      }
      _sendCLOSE(handle);
      return lsEntries;
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to ls path: "+path, e);
    }
  }
View Full Code Here

    }
  }

  public String readlink(String path) throws SftpException {
    if( _serverVersion < 3 ) {
      throw new SftpException(SSH_FX_OP_UNSUPPORTED, "The remote SFTP server is too old to support readlink operation");
    }
    try {
      path = isUnique(remoteAbsolutePath(path));

      sendREADLINK(Util.str2byte(path, _fileEncoding));
      readResponse();
      if( _header.type != SSH_FXP_NAME ) {
        throw new SftpException(SSH_FX_FAILURE, "Invalid FXP response: "+_header.type);
      }

      int count = _buffer.getInt();       // count
      byte[] filename = null;
      for( int i = 0; i < count; i++ ) {
        filename = _buffer.getString()// absolute path
        if( _serverVersion <= 3 ) {
          _buffer.getString();    // long filename
        }
        SftpATTRS.getATTR(_buffer);    // dummy attribute
      }
      return Util.byte2str(filename, _fileEncoding);
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to readlink path: "+path, e);
    }
  }
View Full Code Here

    }
  }

  public void symlink(String oldpath, String newpath) throws SftpException {
    if( _serverVersion < 3 ) {
      throw new SftpException(SSH_FX_OP_UNSUPPORTED, "The remote SFTP server is too old to support symlink operation");
    }
    try {
      oldpath = isUnique(remoteAbsolutePath(oldpath));
      newpath = remoteAbsolutePath(newpath);

      if( isPattern(newpath) ) {
        throw new SftpException(SSH_FX_FAILURE, "Failed to symlink, new path is invalid: "+newpath);
      }
      newpath = Util.unquote(newpath);

      sendSYMLINK(Util.str2byte(oldpath, _fileEncoding), Util.str2byte(newpath, _fileEncoding));
      readResponseOk();
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to symlink path: "+oldpath, e);
    }
  }
View Full Code Here

    }
  }

  public void rename(String oldpath, String newpath) throws SftpException {
    if( _serverVersion < 2 ) {
      throw new SftpException(SSH_FX_OP_UNSUPPORTED, "The remote SFTP server is too old to support rename operation");
    }
    try {
      oldpath = isUnique(remoteAbsolutePath(oldpath));
      newpath = remoteAbsolutePath(newpath);

      List<String> matches = globRemote(newpath);
      if( matches.size() >= 2 ) {
        throw new SftpException(SSH_FX_FAILURE, "Failed to rename path, found too many matches: "+matches);
      } else if( matches.size() == 1 ) {
        newpath = matches.get(0);
      } else {
        if( isPattern(newpath) ) {
          throw new SftpException(SSH_FX_FAILURE, "Failed to rename path, new path is invalid: "+newpath);
        }
        newpath = Util.unquote(newpath);
      }

      sendRENAME(Util.str2byte(oldpath, _fileEncoding), Util.str2byte(newpath, _fileEncoding));
      readResponseOk();
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to rename path: "+oldpath, e);
    }
  }
View Full Code Here

        readResponseOk();
      }
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to rm path: "+path, e);
    }
  }
View Full Code Here

        _setStat(remotePath, attr);
      }
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to chgrp path: "+path, e);
    }
  }
View Full Code Here

        _setStat(remotePath, attr);
      }
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to chown path: "+path, e);
    }
  }
View Full Code Here

        _setStat(remotePath, attr);
      }
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to chmod path: "+path, e);
    }
  }
View Full Code Here

        _setStat(remotePath, attr);
      }
    } catch(SftpException e) {
      throw e;
    } catch(Exception e) {
      throw new SftpException(SSH_FX_FAILURE, "Failed to set mtime path: "+path, e);
    }
  }
View Full Code Here

TOP

Related Classes of org.vngx.jsch.exception.SftpException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.