Search in sources :

Example 1 with org.apache.commons.vfs2

use of org.apache.commons.vfs2 in project pentaho-kettle by pentaho.

the class SftpFileSystemWindows method executeCommand.

/**
 * {@link  org.apache.commons.vfs2.provider.sftp.SftpFileSystem#executeCommand(java.lang.String, java.lang.StringBuilder) }
 */
private int executeCommand(String command, StringBuilder output) throws JSchException, IOException {
    this.ensureSession();
    ChannelExec channel = (ChannelExec) this.session.openChannel("exec");
    channel.setCommand(command);
    channel.setInputStream((InputStream) null);
    InputStreamReader stream = new InputStreamReader(channel.getInputStream());
    channel.setErrStream(System.err, true);
    channel.connect();
    char[] buffer = new char[128];
    int read;
    while ((read = stream.read(buffer, 0, buffer.length)) >= 0) {
        output.append(buffer, 0, read);
    }
    stream.close();
    while (!channel.isClosed()) {
        try {
            Thread.sleep(100L);
        } catch (Exception exc) {
            log.logMinimal("Warning: Error session closing. " + exc.getMessage());
        }
    }
    channel.disconnect();
    return channel.getExitStatus();
}
Also used : InputStreamReader(java.io.InputStreamReader) ChannelExec(com.jcraft.jsch.ChannelExec) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException)

Example 2 with org.apache.commons.vfs2

use of org.apache.commons.vfs2 in project pentaho-kettle by pentaho.

the class SftpFileSystemWindows method ensureSession.

/**
 * {@link  org.apache.commons.vfs2.provider.sftp.SftpFileSystem#getChannel() }
 */
private void ensureSession() throws FileSystemException {
    if (this.session == null || !this.session.isConnected()) {
        this.doCloseCommunicationLink();
        UserAuthenticationData authData = null;
        Session session;
        try {
            GenericFileName e = (GenericFileName) this.getRootName();
            authData = UserAuthenticatorUtils.authenticate(this.getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES);
            session = SftpClientFactory.createConnection(e.getHostName(), e.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(e.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(e.getPassword())), this.getFileSystemOptions());
        } catch (Exception var7) {
            throw new FileSystemException("vfs.provider.sftp/connect.error", this.getRootName(), var7);
        } finally {
            UserAuthenticatorUtils.cleanup(authData);
        }
        this.session = session;
    }
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) GenericFileName(org.apache.commons.vfs2.provider.GenericFileName) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException) Session(com.jcraft.jsch.Session)

Example 3 with org.apache.commons.vfs2

use of org.apache.commons.vfs2 in project jackrabbit by apache.

the class VFSFileSystem method hasChildren.

@Override
public boolean hasChildren(String path) throws FileSystemException {
    try {
        final FileObject fo = resolveFileObject(path);
        if (!fo.exists()) {
            final String msg = "File doesn't exist at " + path + ".";
            log.debug(msg);
            throw new FileSystemException(msg);
        }
        if (fo.isFile()) {
            return false;
        }
        return (fo.getChildren().length > 0);
    } catch (org.apache.commons.vfs2.FileSystemException e) {
        final String msg = "Failed to check if there's any child at " + path + ".";
        log.debug(msg, e);
        throw new FileSystemException(msg, e);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject)

Example 4 with org.apache.commons.vfs2

use of org.apache.commons.vfs2 in project jackrabbit by apache.

the class VFSFileSystem method getInputStream.

@Override
public InputStream getInputStream(String filePath) throws FileSystemException {
    try {
        final FileObject fo = resolveFileObject(filePath);
        final FileObject folder = fo.getParent();
        if (!folder.exists() || !folder.isFolder()) {
            throw new FileSystemException("Folder doesn't exist for " + filePath + ".");
        }
        return new LazyFileContentInputStream(fo);
    } catch (org.apache.commons.vfs2.FileSystemException e) {
        final String msg = "Failed to open an input stream from " + filePath + ".";
        log.debug(msg, e);
        throw new FileSystemException(msg, e);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) LazyFileContentInputStream(org.apache.jackrabbit.vfs.ext.ds.LazyFileContentInputStream) FileObject(org.apache.commons.vfs2.FileObject)

Example 5 with org.apache.commons.vfs2

use of org.apache.commons.vfs2 in project jackrabbit by apache.

the class VFSFileSystem method deleteFolder.

@Override
public void deleteFolder(String folderPath) throws FileSystemException {
    try {
        final FileObject fo = resolveFileObject(folderPath);
        if (!fo.isFolder()) {
            String msg = "Folder doesn't exist at " + folderPath + ".";
            log.debug(msg);
            throw new FileSystemException(msg);
        }
        fo.deleteAll();
    } catch (org.apache.commons.vfs2.FileSystemException e) {
        final String msg = "Failed to delete folder at " + folderPath + ".";
        log.debug(msg, e);
        throw new FileSystemException(msg, e);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)13 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)11 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)6 FileSystemException (org.apache.commons.vfs2.FileSystemException)5 IOException (java.io.IOException)4 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)4 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)4 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)4 FileContentInfoFilenameFactory (org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory)4 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)4 JSchException (com.jcraft.jsch.JSchException)3 File (java.io.File)3 HdfsFileProvider (org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider)3 ChannelExec (com.jcraft.jsch.ChannelExec)2 InputStreamReader (java.io.InputStreamReader)2 LinkedList (java.util.LinkedList)2 DefaultFileReplicator (org.apache.commons.vfs2.impl.DefaultFileReplicator)2 AbstractFileObject (org.apache.commons.vfs2.provider.AbstractFileObject)2 HttpClient (org.apache.http.client.HttpClient)2 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)2