Example usage for org.apache.commons.vfs2.provider.sftp PrincipalProvidedSessionSftpFileSystemConfigBuilder setUserDirIsRoot

List of usage examples for org.apache.commons.vfs2.provider.sftp PrincipalProvidedSessionSftpFileSystemConfigBuilder setUserDirIsRoot

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.provider.sftp PrincipalProvidedSessionSftpFileSystemConfigBuilder setUserDirIsRoot.

Prototype

public void setUserDirIsRoot(FileSystemOptions opts, boolean userDirIsRoot) 

Source Link

Document

use user directory as root (do not change to fs root).

Usage

From source file:org.helios.ember.sftp.SFTPSessionFactory.java

/**
 * <p>Authenticates the passed principal and returns a <i>root</i> sftp file object in accordance with the factory configuration.</p>
 * <p><b>CAUTION!  :</b> This app passes around SSH passwords and private key passphrases which you should NEVER do. It's just a demo until I figure out a better way to do this.<p>
 * //from w w w.j a v a 2  s . co  m
 * @param sessionLogin The principal
 * @param landingDirectory The optional landing directory that the returned <i>root</i> sftp file object will represent. Defaults to the principal's home directory 
 * @return the <i>root</i> sftp file object
 */
public FileObject newSFTPSession(SessionLogin sessionLogin, String landingDirectory) {
    if (sessionLogin == null)
        throw new IllegalArgumentException("The passed principal was null", new Throwable());
    landingDirectory = cleanLandingDirectory(landingDirectory);
    //String sessionUri = String.format(sftpUrl, sessionLogin.getName(), sessionLogin.getHost(), sessionLogin.getPort(), landingDirectory);      
    String sessionUri = String.format(sftpUrl, sessionLogin.getName(), sessionLogin.getHost(),
            landingDirectory);
    log.info("Building session for [" + sessionUri + "]");
    FileSystemOptions fsOptions = new FileSystemOptions();
    PrincipalProvidedSessionSftpFileSystemConfigBuilder builder = PrincipalProvidedSessionSftpFileSystemConfigBuilder
            .getInstance();
    try {
        //builder.setUserDirIsRoot(fsOptions, landingDirectory.trim().isEmpty());
        builder.setUserDirIsRoot(fsOptions, true);
        builder.setRootURI(fsOptions, sessionUri);
        builder.setSession(fsOptions, sessionLogin.getSession());
        return fileSystemManager.resolveFile(sessionUri, fsOptions);
    } catch (FileSystemException fse) {
        throw new RuntimeException("VFS FileSystem Exception", fse);
    } catch (Exception ex) {
        throw new RuntimeException("Unexpected Exception", ex);
    }
}