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();
}
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;
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations