Java Code Examples for com.jcraft.jsch.SftpATTRS#SSH_FILEXFER_ATTR_PERMISSIONS

The following examples show how to use com.jcraft.jsch.SftpATTRS#SSH_FILEXFER_ATTR_PERMISSIONS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SftpClient.java    From hop with Apache License 2.0 6 votes vote down vote up
public FileType getFileType( String filename ) throws HopWorkflowException {
  try {
    SftpATTRS attrs = c.stat( filename );
    if ( attrs == null ) {
      return FileType.IMAGINARY;
    }

    if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) {
      throw new HopWorkflowException( "Unknown permissions error" );
    }

    if ( attrs.isDir() ) {
      return FileType.FOLDER;
    } else {
      return FileType.FILE;
    }
  } catch ( Exception e ) {
    throw new HopWorkflowException( e );
  }
}
 
Example 2
Source File: SftpClient.java    From hop with Apache License 2.0 6 votes vote down vote up
public boolean folderExists( String foldername ) {
  boolean retval = false;
  try {
    SftpATTRS attrs = c.stat( foldername );
    if ( attrs == null ) {
      return false;
    }

    if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) {
      throw new HopWorkflowException( "Unknown permissions error" );
    }

    retval = attrs.isDir();
  } catch ( Exception e ) {
    // Folder can not be found!
  }
  return retval;
}
 
Example 3
Source File: SftpFileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the type of this file, returns null if the file does not exist.
 */
@Override
protected FileType doGetType() throws Exception {
    if (attrs == null) {
        statSelf();
    }

    if (attrs == null) {
        return FileType.IMAGINARY;
    }

    if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0) {
        throw new FileSystemException("vfs.provider.sftp/unknown-permissions.error");
    }
    if (attrs.isDir()) {
        return FileType.FOLDER;
    }
    return FileType.FILE;
}
 
Example 4
Source File: AbstractSftpProviderTestCase.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
private SftpAttrs(final Buffer buf) {
    int flags = 0;
    flags = buf.getInt();

    if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) != 0) {
        size = buf.getLong();
    }
    if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_UIDGID) != 0) {
        uid = buf.getInt();
        gid = buf.getInt();
    }
    if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) != 0) {
        permissions = buf.getInt();
    }
    if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0) {
        atime = buf.getInt();
    }
    if ((flags & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0) {
        mtime = buf.getInt();
    }

}
 
Example 5
Source File: SFTPClient.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public FileType getFileType( String filename ) throws KettleJobException {
  try {
    SftpATTRS attrs = c.stat( filename );
    if ( attrs == null ) {
      return FileType.IMAGINARY;
    }

    if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) {
      throw new KettleJobException( "Unknown permissions error" );
    }

    if ( attrs.isDir() ) {
      return FileType.FOLDER;
    } else {
      return FileType.FILE;
    }
  } catch ( Exception e ) {
    throw new KettleJobException( e );
  }
}
 
Example 6
Source File: SFTPClient.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean folderExists( String foldername ) {
  boolean retval = false;
  try {
    SftpATTRS attrs = c.stat( foldername );
    if ( attrs == null ) {
      return false;
    }

    if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) {
      throw new KettleJobException( "Unknown permissions error" );
    }

    retval = attrs.isDir();
  } catch ( Exception e ) {
    // Folder can not be found!
  }
  return retval;
}