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
IOException
public void init(Connection con, String protocolInUse) throws IOException
FileSystem
PublicKeyStore
.
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 FileSystem
protocolInUse
- the protocol in useIOException
protected void addMount(String vfspath, String nfspath) throws IOException
IOException
public void closeFilesystem()
FileSystem
closeFilesystem
in interface FileSystem
public String translateNFSPath(String nfspath) throws IOException, FileNotFoundException
IOException
FileNotFoundException
protected VFSMount getMount(String vfspath) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public String translateVFSPath(String vfspath) throws IOException, FileNotFoundException
IOException
FileNotFoundException
protected String translateCanonicalPath(String path, String securemount) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public boolean makeDirectory(String path, SftpFileAttributes attrs) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
makeDirectory
in interface FileSystem
path
- String the absolute path to the new directory.PermissionDeniedException
- if the user cannot perform this
operation.FileNotFoundException
- if the parent directory does not exist.IOException
public SftpFileAttributes getFileAttributes(byte[] handle) throws IOException, InvalidHandleException
FileSystem
getFileAttributes
in interface FileSystem
handle
- byte[]IOException
InvalidHandleException
public SftpFileAttributes getFileAttributes(String path) throws IOException, FileNotFoundException
FileSystem
getFileAttributes
in interface FileSystem
path
- String the absolute path to the fileIOException
FileNotFoundException
- if the file cannot be foundSftpFileAttributes
public byte[] openDirectory(String path) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
openDirectory
in interface FileSystem
path
- StringPermissionDeniedException
FileNotFoundException
IOException
public SftpFile[] readDirectory(byte[] handle) throws InvalidHandleException, EOFException, IOException
FileSystem
Read 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 FileSystem
handle
- 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
FileSystem
openFile
in interface FileSystem
path
- Stringflags
- UnsignedInteger32attrs
- SftpFileAttributesPermissionDeniedException
FileNotFoundException
IOException
public int readFile(byte[] handle, com.maverick.util.UnsignedInteger64 offset, byte[] buf, int start, int numBytesToRead) throws InvalidHandleException, EOFException, IOException
FileSystem
readFile
in interface FileSystem
handle
- byte[]offset
- UnsignedInteger64buf
- byte[]start
- intnumBytesToRead
- intInvalidHandleException
EOFException
IOException
public void writeFile(byte[] handle, com.maverick.util.UnsignedInteger64 offset, byte[] data, int off, int len) throws InvalidHandleException, IOException
FileSystem
writeFile
in interface FileSystem
handle
- byte[]offset
- UnsignedInteger64data
- byte[]off
- intlen
- intInvalidHandleException
IOException
public void closeFile(byte[] handle) throws InvalidHandleException, IOException
FileSystem
closeFile
in interface FileSystem
handle
- byte[]InvalidHandleException
IOException
public boolean closeFile(byte[] handle, boolean remove) throws InvalidHandleException, IOException
InvalidHandleException
IOException
public void removeFile(String path) throws PermissionDeniedException, IOException, FileNotFoundException
FileSystem
removeFile
in interface FileSystem
path
- StringPermissionDeniedException
IOException
FileNotFoundException
public void renameFile(String oldpath, String newpath) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
renameFile
in interface FileSystem
oldpath
- Stringnewpath
- StringPermissionDeniedException
FileNotFoundException
IOException
public String getDefaultPath()
FileSystem
getDefaultPath
in interface FileSystem
public void removeDirectory(String path) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
removeDirectory
in interface FileSystem
path
- StringPermissionDeniedException
FileNotFoundException
IOException
public void setFileAttributes(String path, SftpFileAttributes attrs) throws PermissionDeniedException, IOException, FileNotFoundException
FileSystem
setFileAttributes
in interface FileSystem
path
- Stringattrs
- SftpFileAttributesPermissionDeniedException
IOException
FileNotFoundException
public void setFileAttributes(byte[] handle, SftpFileAttributes attrs) throws PermissionDeniedException, IOException, InvalidHandleException
FileSystem
setFileAttributes
in interface FileSystem
handle
- byte[]attrs
- SftpFileAttributesPermissionDeniedException
IOException
InvalidHandleException
public SftpFile readSymbolicLink(String path) throws UnsupportedFileOperationException, FileNotFoundException, IOException, PermissionDeniedException
FileSystem
readSymbolicLink
in interface FileSystem
path
- StringUnsupportedFileOperationException
FileNotFoundException
IOException
PermissionDeniedException
public void createSymbolicLink(String link, String target) throws UnsupportedFileOperationException, FileNotFoundException, IOException, PermissionDeniedException
FileSystem
createSymbolicLink
in interface FileSystem
link
- Stringtarget
- StringUnsupportedFileOperationException
FileNotFoundException
IOException
PermissionDeniedException
public boolean fileExists(String path) throws IOException
FileSystem
fileExists
in interface FileSystem
path
- StringIOException
public String getRealPath(String path) throws IOException, FileNotFoundException
FileSystem
getRealPath
in interface FileSystem
path
- 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
FileSystem
getPathForHandle
in interface FileSystem
InvalidHandleException
public void populateEvent(com.maverick.events.Event event)
FileSystem
populateEvent
in interface FileSystem
Copyright © 2017. All rights reserved.