I am trying to create a read only VirtualFileSystemFactory for a custom sftp server using Apache Mina SSHD library. I have searched a lot but it seems that I cant find the solution to this problem. IS there maybe someone who knows how to do this ?
Here is my VirtualFileSystemFactory
VirtualFileSystemFactory virtualFileSystemFactory = new VirtualFileSystemFactory() {
@Override
public FileSystem createFileSystem(Session session) throws IOException {
String username = session.getUsername();
Path dir = Paths.get("c:\\data\\");
if (dir == null) {
throw new InvalidPathException(username, "Cannot resolve home directory");
} else {
return (new RootedFileSystemProvider()).newFileSystem(dir, Collections.emptyMap());
}
}
};
// Virtual Factory
sshd.setFileSystemFactory(virtualFileSystemFactory);
I had the same issue. As you can see
VirtualFileSystemFactoryis creating aRootedFileSystemProviderwhich contains the file system operations. You can extend both classes to get your customized one.As I tested the Scp commands and SFTP interface this overridden code can prevent the client from making changes, however, you can change it to your needs.