|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.maverick.sshd.vfs.VirtualFileSystem
public class VirtualFileSystem
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.
| Field Summary |
|---|
| Fields inherited from interface com.maverick.sshd.platform.FileSystem |
|---|
AUTHORIZED_KEYS_STORE, OPEN_APPEND, OPEN_CREATE, OPEN_EXCLUSIVE, OPEN_READ, OPEN_TRUNCATE, OPEN_WRITE, SCP, SFTP, SSH |
| Constructor Summary | |
|---|---|
VirtualFileSystem()
|
|
| Method Summary | |
|---|---|
protected void |
addMount(java.lang.String vfspath,
java.lang.String nfspath)
|
void |
closeFile(byte[] handle)
Close an open file or directory. |
boolean |
closeFile(byte[] handle,
boolean remove)
|
void |
closeFilesystem()
The filesystem instance is being closed and no further use of the instance is required. |
void |
createSymbolicLink(java.lang.String link,
java.lang.String target)
Create a symbolic link. |
boolean |
fileExists(java.lang.String path)
Determine whether a file exists and return the result |
java.lang.String |
getDefaultPath()
Get the default path for the current session. |
SftpFileAttributes |
getFileAttributes(byte[] handle)
Get the attributes for a given file handle. |
SftpFileAttributes |
getFileAttributes(java.lang.String path)
Get the attributes for a given file. |
java.lang.String |
getRealPath(java.lang.String path)
Get the real path for a given path. |
void |
init(Connection con,
java.lang.String protocolInUse)
|
boolean |
makeDirectory(java.lang.String path)
Create a directory. |
byte[] |
openDirectory(java.lang.String path)
Open a directory for reading and allocate an open file handle. |
byte[] |
openFile(java.lang.String path,
com.maverick.util.UnsignedInteger32 flags,
SftpFileAttributes attrs)
Open a file for reading/writing and allocate an open file handle. |
SftpFile[] |
readDirectory(byte[] handle)
Read the contents of a directory. |
int |
readFile(byte[] handle,
com.maverick.util.UnsignedInteger64 offset,
byte[] buf,
int start,
int numBytesToRead)
Read a block of data from an open file. |
SftpFile |
readSymbolicLink(java.lang.String path)
Read the target location of a symbolic link. |
void |
removeDirectory(java.lang.String path)
Remove an empty directory from the file system. |
void |
removeFile(java.lang.String path)
Remove a file. |
void |
renameFile(java.lang.String oldpath,
java.lang.String newpath)
Rename a file. |
void |
setFileAttributes(byte[] handle,
SftpFileAttributes attrs)
Set the open files attributes |
void |
setFileAttributes(java.lang.String path,
SftpFileAttributes attrs)
Set the files attributes. |
protected java.lang.String |
translateCanonicalPath(java.lang.String path,
java.lang.String securemount)
|
java.lang.String |
translateNFSPath(java.lang.String nfspath)
|
java.lang.String |
translateVFSPath(java.lang.String vfspath)
|
void |
writeFile(byte[] handle,
com.maverick.util.UnsignedInteger64 offset,
byte[] data,
int off,
int len)
Write a block of data to an open file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public VirtualFileSystem()
| Method Detail |
|---|
public void init(Connection con,
java.lang.String protocolInUse)
throws java.io.IOException
java.io.IOException
protected void addMount(java.lang.String vfspath,
java.lang.String nfspath)
throws java.io.IOException
java.io.IOExceptionpublic void closeFilesystem()
FileSystem
closeFilesystem in interface FileSystem
public java.lang.String translateNFSPath(java.lang.String nfspath)
throws java.io.IOException,
java.io.FileNotFoundException
java.io.IOException
java.io.FileNotFoundException
public java.lang.String translateVFSPath(java.lang.String vfspath)
throws java.io.IOException,
java.io.FileNotFoundException
java.io.IOException
java.io.FileNotFoundException
protected java.lang.String translateCanonicalPath(java.lang.String path,
java.lang.String securemount)
throws java.io.FileNotFoundException,
java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public boolean makeDirectory(java.lang.String path)
throws PermissionDeniedException,
java.io.FileNotFoundException,
java.io.IOException
FileSystem
makeDirectory in interface FileSystempath - String the absolute path to the new directory.
PermissionDeniedException - if the user cannot perform this
operation.
java.io.FileNotFoundException - if the parent directory does not exist.
java.io.IOException
public SftpFileAttributes getFileAttributes(byte[] handle)
throws java.io.IOException,
InvalidHandleException
FileSystem
getFileAttributes in interface FileSystemhandle - byte[]
java.io.IOException
InvalidHandleException
public SftpFileAttributes getFileAttributes(java.lang.String path)
throws java.io.IOException,
java.io.FileNotFoundException
FileSystem
getFileAttributes in interface FileSystempath - String the absolute path to the file
java.io.IOException
java.io.FileNotFoundException - if the file cannot be foundcom.maverick.sftp.SftpFileAttributes
public byte[] openDirectory(java.lang.String path)
throws PermissionDeniedException,
java.io.FileNotFoundException,
java.io.IOException
FileSystem
openDirectory in interface FileSystempath - String
PermissionDeniedException
java.io.FileNotFoundException
java.io.IOException
public SftpFile[] readDirectory(byte[] handle)
throws InvalidHandleException,
java.io.EOFException,
java.io.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.
java.io.EOFException - thrown once all the files contained with the
directory have been read.
java.io.IOException - an error occurred
public byte[] openFile(java.lang.String path,
com.maverick.util.UnsignedInteger32 flags,
SftpFileAttributes attrs)
throws PermissionDeniedException,
java.io.FileNotFoundException,
java.io.IOException
FileSystem
openFile in interface FileSystempath - Stringflags - UnsignedInteger32attrs - SftpFileAttributes
PermissionDeniedException
java.io.FileNotFoundException
java.io.IOException
public int readFile(byte[] handle,
com.maverick.util.UnsignedInteger64 offset,
byte[] buf,
int start,
int numBytesToRead)
throws InvalidHandleException,
java.io.EOFException,
java.io.IOException
FileSystem
readFile in interface FileSystemhandle - byte[]offset - UnsignedInteger64buf - byte[]start - intnumBytesToRead - int
InvalidHandleException
java.io.EOFException
java.io.IOException
public void writeFile(byte[] handle,
com.maverick.util.UnsignedInteger64 offset,
byte[] data,
int off,
int len)
throws InvalidHandleException,
java.io.IOException
FileSystem
writeFile in interface FileSystemhandle - byte[]offset - UnsignedInteger64data - byte[]off - intlen - int
InvalidHandleException
java.io.IOException
public void closeFile(byte[] handle)
throws InvalidHandleException,
java.io.IOException
FileSystem
closeFile in interface FileSystemhandle - byte[]
InvalidHandleException
java.io.IOException
public boolean closeFile(byte[] handle,
boolean remove)
throws InvalidHandleException,
java.io.IOException
InvalidHandleException
java.io.IOException
public void removeFile(java.lang.String path)
throws PermissionDeniedException,
java.io.IOException,
java.io.FileNotFoundException
FileSystem
removeFile in interface FileSystempath - String
PermissionDeniedException
java.io.IOException
java.io.FileNotFoundException
public void renameFile(java.lang.String oldpath,
java.lang.String newpath)
throws PermissionDeniedException,
java.io.FileNotFoundException,
java.io.IOException
FileSystem
renameFile in interface FileSystemoldpath - Stringnewpath - String
PermissionDeniedException
java.io.FileNotFoundException
java.io.IOExceptionpublic java.lang.String getDefaultPath()
FileSystem
getDefaultPath in interface FileSystem
public void removeDirectory(java.lang.String path)
throws PermissionDeniedException,
java.io.FileNotFoundException,
java.io.IOException
FileSystem
removeDirectory in interface FileSystempath - String
PermissionDeniedException
java.io.FileNotFoundException
java.io.IOException
public void setFileAttributes(java.lang.String path,
SftpFileAttributes attrs)
throws PermissionDeniedException,
java.io.IOException,
java.io.FileNotFoundException
FileSystem
setFileAttributes in interface FileSystempath - Stringattrs - SftpFileAttributes
PermissionDeniedException
java.io.IOException
java.io.FileNotFoundException
public void setFileAttributes(byte[] handle,
SftpFileAttributes attrs)
throws PermissionDeniedException,
java.io.IOException,
InvalidHandleException
FileSystem
setFileAttributes in interface FileSystemhandle - byte[]attrs - SftpFileAttributes
PermissionDeniedException
java.io.IOException
InvalidHandleException
public SftpFile readSymbolicLink(java.lang.String path)
throws UnsupportedFileOperationException,
java.io.FileNotFoundException,
java.io.IOException,
PermissionDeniedException
FileSystem
readSymbolicLink in interface FileSystempath - String
UnsupportedFileOperationException
java.io.FileNotFoundException
java.io.IOException
PermissionDeniedException
public void createSymbolicLink(java.lang.String link,
java.lang.String target)
throws UnsupportedFileOperationException,
java.io.FileNotFoundException,
java.io.IOException,
PermissionDeniedException
FileSystem
createSymbolicLink in interface FileSystemlink - Stringtarget - String
UnsupportedFileOperationException
java.io.FileNotFoundException
java.io.IOException
PermissionDeniedException
public boolean fileExists(java.lang.String path)
throws java.io.IOException
FileSystem
fileExists in interface FileSystempath - String
java.io.IOException
public java.lang.String getRealPath(java.lang.String path)
throws java.io.IOException,
java.io.FileNotFoundException
FileSystem
getRealPath in interface FileSystempath - String the path to canonicalize.
java.io.IOException - if an unrecoverable error occurs.
java.io.FileNotFoundException - if the path cannot be found.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||