public class VirtualFileSystem extends Object implements FileSystem
Provides a platform independent file system that uses standard java file operations. The virtual file system operates on a set of 'mounts' that map a virtual directory to a physical location on the server.
To configure the file system use the following code in your
com.maverick.sshd.SshDaemon#configure(ConfigurationContext)
implementation:
context.setFileSystemProvider(VirtualFileSystem.class);
Mounts can be created by setting system properties and only one property is required "com.maverick.sshd.vfs.VFSRoot". This instructs the server where to look for the root of the file system "/". For example if you wanted to provide access to the root of a windows machine you could set the following property
System.setProperty("com.maverick.sshd.vfs.VFSRoot", "C:\\");
Additional mounts can be set using "com.maverick.sshd.vfs.VFSMount.1" "com.maverick.sshd.vfs.VFSMount.2" and so forth. These mounts must start with a "/" and also have a descriptive name. For example to set the virtual path "/documents" you could use the following property:
System.setProperty("com.maverick.sshd.vfs.VFSMount.1",
"/documents=C:\\My Documents");
The setting of attributes is NOT supported within the virtual file system and
by default users will have access to all files and folders. You can
optionally implement your own VFSPermissionHandler that will enable
you to restrict access to files based on user/group permissions. To configure
the file system with your handler simply set the
"com.maverick.sshd.vfs.VFSPermissionHandler" system property to the
fully qualified class name of your class. This will be installed whenever an
instance of the VirtualFileSystem is created.
The file system also maps the /home/USERNAME to the users home directory.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
lockFiles
Deprecated.
|
AUTHORIZED_KEYS_STORE, OPEN_APPEND, OPEN_CREATE, OPEN_EXCLUSIVE, OPEN_READ, OPEN_TEXT, OPEN_TRUNCATE, OPEN_WRITE, SCP, SFTP, SHELL| Constructor and Description |
|---|
VirtualFileSystem()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addMount(String vfspath,
String nfspath)
Deprecated.
|
void |
closeFile(byte[] handle)
Deprecated.
Close an open file or directory.
|
boolean |
closeFile(byte[] handle,
boolean remove)
Deprecated.
|
void |
closeFilesystem()
Deprecated.
The filesystem instance is being closed and no further use of the
instance is required.
|
void |
createSymbolicLink(String link,
String target)
Deprecated.
Create a symbolic link.
|
boolean |
fileExists(String path)
Deprecated.
Determine whether a file exists and return the result
|
String |
getDefaultPath()
Deprecated.
Get the default path for the current session.
|
SftpFileAttributes |
getFileAttributes(byte[] handle)
Deprecated.
Get the attributes for a given file handle.
|
SftpFileAttributes |
getFileAttributes(String path)
Deprecated.
Get the attributes for a given file.
|
protected VFSMount |
getMount(String vfspath)
Deprecated.
|
String |
getPathForHandle(byte[] handle)
Deprecated.
Return the path for a given handle.
|
String |
getRealPath(String path)
Deprecated.
Get the real path for a given path.
|
void |
init(Connection con,
String protocolInUse)
Deprecated.
Initialize the file system.
|
void |
init(Connection con,
String protocolInUse,
VFSMount homeMount,
VFSMount rootMount,
List<VFSMount> additonalMounts,
VFSPermissionHandler permissionHandler)
Deprecated.
|
boolean |
makeDirectory(String path,
SftpFileAttributes attrs)
Deprecated.
Create a directory.
|
byte[] |
openDirectory(String path)
Deprecated.
Open a directory for reading and allocate an open file handle.
|
byte[] |
openFile(String path,
com.maverick.util.UnsignedInteger32 flags,
SftpFileAttributes attrs)
Deprecated.
Open a file for reading/writing and allocate an open file handle.
|
void |
populateEvent(com.maverick.events.Event event)
Deprecated.
Populate any extra fields in a file system event.
|
SftpFile[] |
readDirectory(byte[] handle)
Deprecated.
Read the contents of a directory.
|
int |
readFile(byte[] handle,
com.maverick.util.UnsignedInteger64 offset,
byte[] buf,
int start,
int numBytesToRead)
Deprecated.
Read a block of data from an open file.
|
SftpFile |
readSymbolicLink(String path)
Deprecated.
Read the target location of a symbolic link.
|
void |
removeDirectory(String path)
Deprecated.
Remove an empty directory from the file system.
|
void |
removeFile(String path)
Deprecated.
Remove a file.
|
void |
renameFile(String oldpath,
String newpath)
Deprecated.
Rename a file.
|
void |
setFileAttributes(byte[] handle,
SftpFileAttributes attrs)
Deprecated.
Set the open files attributes
|
void |
setFileAttributes(String path,
SftpFileAttributes attrs)
Deprecated.
Set the files attributes.
|
protected String |
translateCanonicalPath(String path,
String securemount)
Deprecated.
|
String |
translateNFSPath(String nfspath)
Deprecated.
|
String |
translateVFSPath(String vfspath)
Deprecated.
|
void |
writeFile(byte[] handle,
com.maverick.util.UnsignedInteger64 offset,
byte[] data,
int off,
int len)
Deprecated.
Write a block of data to an open file.
|
public void init(Connection con, String protocolInUse, VFSMount homeMount, VFSMount rootMount, List<VFSMount> additonalMounts, VFSPermissionHandler permissionHandler) throws IOException
IOExceptionpublic void init(Connection con, String protocolInUse) throws IOException
FileSystemPublicKeyStore.
When this happens the method will receive a null session object, it is
recommended that you do not rely on a
SessionChannel being availble. In most cases
this was used to detect the closing of the channel, and therefore the
file system and to resolve this a new method has been added
FileSystem.closeFilesystem().init in interface FileSystemprotocolInUse - the protocol in useIOExceptionprotected void addMount(String vfspath, String nfspath) throws IOException
IOExceptionpublic void closeFilesystem()
FileSystemcloseFilesystem in interface FileSystempublic String translateNFSPath(String nfspath) throws IOException, FileNotFoundException
IOExceptionFileNotFoundExceptionprotected VFSMount getMount(String vfspath) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic String translateVFSPath(String vfspath) throws IOException, FileNotFoundException
IOExceptionFileNotFoundExceptionprotected String translateCanonicalPath(String path, String securemount) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic boolean makeDirectory(String path, SftpFileAttributes attrs) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemmakeDirectory in interface FileSystempath - String the absolute path to the new directory.PermissionDeniedException - if the user cannot perform this
operation.FileNotFoundException - if the parent directory does not exist.IOExceptionpublic SftpFileAttributes getFileAttributes(byte[] handle) throws IOException, InvalidHandleException
FileSystemgetFileAttributes in interface FileSystemhandle - byte[]IOExceptionInvalidHandleExceptionpublic SftpFileAttributes getFileAttributes(String path) throws IOException, FileNotFoundException
FileSystemgetFileAttributes in interface FileSystempath - String the absolute path to the fileIOExceptionFileNotFoundException - if the file cannot be foundSftpFileAttributespublic byte[] openDirectory(String path) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemopenDirectory in interface FileSystempath - StringPermissionDeniedExceptionFileNotFoundExceptionIOExceptionpublic SftpFile[] readDirectory(byte[] handle) throws InvalidHandleException, EOFException, IOException
FileSystemRead the contents of a directory. Each call to this method should return one or more file objects with full file attributes for each file. The client will call this method repeatedly until an EOFException is thrown indicating that there are no more files to read from the directory. If there are no files to list then the EOFException should be thrown upon first call.
IMPORTANT: Each SftpFile object should be initialized with the relative path of the file AND NOT the absolute path.
readDirectory in interface FileSystemhandle - byte[]InvalidHandleException - the handle supplied is invalid.EOFException - thrown once all the files contained with the
directory have been read.IOException - an error occurredpublic byte[] openFile(String path, com.maverick.util.UnsignedInteger32 flags, SftpFileAttributes attrs) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemopenFile in interface FileSystempath - Stringflags - UnsignedInteger32attrs - SftpFileAttributesPermissionDeniedExceptionFileNotFoundExceptionIOExceptionpublic int readFile(byte[] handle,
com.maverick.util.UnsignedInteger64 offset,
byte[] buf,
int start,
int numBytesToRead)
throws InvalidHandleException,
EOFException,
IOException
FileSystemreadFile in interface FileSystemhandle - byte[]offset - UnsignedInteger64buf - byte[]start - intnumBytesToRead - intInvalidHandleExceptionEOFExceptionIOExceptionpublic void writeFile(byte[] handle,
com.maverick.util.UnsignedInteger64 offset,
byte[] data,
int off,
int len)
throws InvalidHandleException,
IOException
FileSystemwriteFile in interface FileSystemhandle - byte[]offset - UnsignedInteger64data - byte[]off - intlen - intInvalidHandleExceptionIOExceptionpublic void closeFile(byte[] handle)
throws InvalidHandleException,
IOException
FileSystemcloseFile in interface FileSystemhandle - byte[]InvalidHandleExceptionIOExceptionpublic boolean closeFile(byte[] handle,
boolean remove)
throws InvalidHandleException,
IOException
InvalidHandleExceptionIOExceptionpublic void removeFile(String path) throws PermissionDeniedException, IOException, FileNotFoundException
FileSystemremoveFile in interface FileSystempath - StringPermissionDeniedExceptionIOExceptionFileNotFoundExceptionpublic void renameFile(String oldpath, String newpath) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemrenameFile in interface FileSystemoldpath - Stringnewpath - StringPermissionDeniedExceptionFileNotFoundExceptionIOExceptionpublic String getDefaultPath()
FileSystemgetDefaultPath in interface FileSystempublic void removeDirectory(String path) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemremoveDirectory in interface FileSystempath - StringPermissionDeniedExceptionFileNotFoundExceptionIOExceptionpublic void setFileAttributes(String path, SftpFileAttributes attrs) throws PermissionDeniedException, IOException, FileNotFoundException
FileSystemsetFileAttributes in interface FileSystempath - Stringattrs - SftpFileAttributesPermissionDeniedExceptionIOExceptionFileNotFoundExceptionpublic void setFileAttributes(byte[] handle,
SftpFileAttributes attrs)
throws PermissionDeniedException,
IOException,
InvalidHandleException
FileSystemsetFileAttributes in interface FileSystemhandle - byte[]attrs - SftpFileAttributesPermissionDeniedExceptionIOExceptionInvalidHandleExceptionpublic SftpFile readSymbolicLink(String path) throws UnsupportedFileOperationException, FileNotFoundException, IOException, PermissionDeniedException
FileSystemreadSymbolicLink in interface FileSystempath - StringUnsupportedFileOperationExceptionFileNotFoundExceptionIOExceptionPermissionDeniedExceptionpublic void createSymbolicLink(String link, String target) throws UnsupportedFileOperationException, FileNotFoundException, IOException, PermissionDeniedException
FileSystemcreateSymbolicLink in interface FileSystemlink - Stringtarget - StringUnsupportedFileOperationExceptionFileNotFoundExceptionIOExceptionPermissionDeniedExceptionpublic boolean fileExists(String path) throws IOException
FileSystemfileExists in interface FileSystempath - StringIOExceptionpublic String getRealPath(String path) throws IOException, FileNotFoundException
FileSystemgetRealPath in interface FileSystempath - String the path to canonicalize.IOException - if an unrecoverable error occurs.FileNotFoundException - if the path cannot be found.public String getPathForHandle(byte[] handle) throws InvalidHandleException
FileSystemgetPathForHandle in interface FileSystemInvalidHandleExceptionpublic void populateEvent(com.maverick.events.Event event)
FileSystempopulateEvent in interface FileSystemCopyright © 2017. All rights reserved.