Class SftpFileSystem
java.lang.Object
org.apache.commons.vfs2.provider.AbstractVfsComponent
org.apache.commons.vfs2.provider.AbstractFileSystem
org.apache.commons.vfs2.provider.sftp.SftpFileSystem
- All Implemented Interfaces:
Closeable,AutoCloseable,FileSystem,VfsComponent
Represents the files on an SFTP server.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Durationprivate static final intprivate final booleanSome SFTP-only servers disable the exec channel.private int[]Cache for the user groups ids (null when not set)private com.jcraft.jsch.ChannelSftpprivate static final longprivate static final org.apache.commons.logging.Logprivate com.jcraft.jsch.SessionSession; never null.private static final intprivate intCache for the user ID (-1 when not set)private static final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSftpFileSystem(GenericFileName rootName, com.jcraft.jsch.Session session, FileSystemOptions fileSystemOptions) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCapabilities(Collection<Capability> caps) Adds the capabilities of this file system.protected FileObjectcreateFile(AbstractFileName name) Creates a file object.private booleanSome SFTP-only servers disable the exec channel.protected voidCloses the underlying link used to access the files.private intexecuteCommand(String command, StringBuilder output) Executes a command and returns the (standard) output through a StringBuilder.protected com.jcraft.jsch.ChannelSftpReturns an SFTP channel to the server.int[]Gets the (numeric) group IDs.doubleLast modification time is only an int and in seconds, thus can be off by 999.private com.jcraft.jsch.SessionEnsures that the session link is established.intgetUId()Gets the (numeric) group IDs.booleanprotected voidputChannel(com.jcraft.jsch.ChannelSftp channelSftp) Returns a channel to the pool.Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileSystem
addJunction, addListener, close, closeCommunicationLink, decorateFileObject, doReplicateFile, fireFileChanged, fireFileCreated, fireFileDeleted, getAttribute, getFileFromCache, getFileSystemManager, getFileSystemOptions, getParentLayer, getRoot, getRootName, getRootURI, hasCapability, init, isOpen, isReleaseable, notifyAllStreamsClosed, putFileToCache, removeFileFromCache, removeJunction, removeListener, replicateFile, resolveFile, resolveFile, setAttributeMethods inherited from class org.apache.commons.vfs2.provider.AbstractVfsComponent
getContext, getLogger, setContext, setLogger
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
UNIDENTIFED
private static final int UNIDENTIFED- See Also:
-
SLEEP_MILLIS
private static final int SLEEP_MILLIS- See Also:
-
EXEC_BUFFER_SIZE
private static final int EXEC_BUFFER_SIZE- See Also:
-
LAST_MOD_TIME_ACCURACY
private static final long LAST_MOD_TIME_ACCURACY- See Also:
-
session
private volatile com.jcraft.jsch.Session sessionSession; never null.DCL pattern requires that the ivar be volatile.
-
idleChannel
private volatile com.jcraft.jsch.ChannelSftp idleChannel -
connectTimeout
-
uid
private volatile int uidCache for the user ID (-1 when not set)DCL pattern requires that the ivar be volatile.
-
groupsIds
private volatile int[] groupsIdsCache for the user groups ids (null when not set)DCL pattern requires that the ivar be volatile.
-
execDisabled
private final boolean execDisabledSome SFTP-only servers disable the exec channel. When exec is disabled, things like getUId() will always fail.
-
-
Constructor Details
-
SftpFileSystem
protected SftpFileSystem(GenericFileName rootName, com.jcraft.jsch.Session session, FileSystemOptions fileSystemOptions)
-
-
Method Details
-
addCapabilities
Adds the capabilities of this file system.- Specified by:
addCapabilitiesin classAbstractFileSystem- Parameters:
caps- collections of Capabilities, can be immutable.
-
createFile
Creates a file object. This method is called only if the requested file is not cached.- Specified by:
createFilein classAbstractFileSystem- Parameters:
name- name referencing the new file.- Returns:
- new created FileObject.
- Throws:
FileSystemException
-
detectExecDisabled
private boolean detectExecDisabled()Some SFTP-only servers disable the exec channel. Attempt to detect this by calling getUid. -
doCloseCommunicationLink
protected void doCloseCommunicationLink()Description copied from class:AbstractFileSystemCloses the underlying link used to access the files.- Overrides:
doCloseCommunicationLinkin classAbstractFileSystem
-
executeCommand
private int executeCommand(String command, StringBuilder output) throws com.jcraft.jsch.JSchException, IOException Executes a command and returns the (standard) output through a StringBuilder.- Parameters:
command- The commandoutput- The output- Returns:
- The exit code of the command
- Throws:
com.jcraft.jsch.JSchException- if a JSch error is detected.FileSystemException- if a session cannot be created.IOException- if an I/O error is detected.
-
getChannel
Returns an SFTP channel to the server.- Returns:
- new or reused channel, never null.
- Throws:
FileSystemException- if a session cannot be created.IOException- if an I/O error is detected.
-
getGroupsIds
Gets the (numeric) group IDs.- Returns:
- the (numeric) group IDs.
- Throws:
com.jcraft.jsch.JSchException- If a problem occurs while retrieving the group IDs.IOException- if an I/O error is detected.- Since:
- 2.1
-
getLastModTimeAccuracy
public double getLastModTimeAccuracy()Last modification time is only an int and in seconds, thus can be off by 999.- Specified by:
getLastModTimeAccuracyin interfaceFileSystem- Overrides:
getLastModTimeAccuracyin classAbstractFileSystem- Returns:
- 1000
-
getSession
Ensures that the session link is established.- Throws:
FileSystemException- if a session cannot be created.
-
getUId
Gets the (numeric) group IDs.- Returns:
- The numeric user ID
- Throws:
com.jcraft.jsch.JSchException- If a problem occurs while retrieving the group ID.IOException- if an I/O error is detected.- Since:
- 2.1
-
isExecDisabled
public boolean isExecDisabled()- Returns:
- Whether the exec channel is disabled.
- See Also:
-
putChannel
protected void putChannel(com.jcraft.jsch.ChannelSftp channelSftp) Returns a channel to the pool.- Parameters:
channelSftp- the SFTP channel.
-