Give user home directory in Custom FileSystem

0 votes
asked Jun 19 by MattiasAndries (120 points)

Hi,

I am implementing a sftp solution with a custom File System provider(azure file system).
I am trying to give ftp users a specific home directory using the Virtual Root Path property but I am unable to make it work.

Let's say I have this file structure in Azure:
/
user1/
user2/
user3/

where / is root and the child directories would be the home directories of the different users.

The code I have is this:

var user = new FileServerUser(userName, userPassword, "/user1");

// use the custom file system provider as this user's virtual file system
user.SetFileSystem(azureFs);

When I run this, I get an exception saying "Existing path required."

Is there something that I am missing?

thanks,
Mattias

Applies to: Rebex SFTP

1 Answer

0 votes
answered Jun 19 by renestein (2,790 points)
edited Jun 19 by renestein

Hi Mattias,
and welcome to the Rebex Forum. Thanks for reporting this issue.
You are experiencing some clashes between the SFTP server API and the new Virtual File System API. We are aware of this. We are improving our documentation and we are discussing how to improve the API.

However, the solution is simple. You can limit a user to a specific directory using the DirectoryFileSystemProvider.

         var userDirectory = azureFs.Root.GetDirectories()                                                             
                .SingleOrDefault(dir => dir.Name.Equals("user1", StringComparison.OrdinalIgnoreCase));
 //Every directory in the file system can serve as a FileSystemProvider. 
//Use the CreateFileSystem method and you are done.        
               var userDirectoryFS = userDirectory.CreateFileSystem();
               var user = new FileServerUser(userName,userPassword);
               user.SetFileSystem(userDirectoryFS);
commented Jun 20 by RussPhillips (100 points)

If you did something like already provide the user's folder path and did a azureFs.Mount... then just calling the FileServerUser with only 2 parameters might work.

var user = new FileServerUser(userName, userPassword);

Or (depending on what you are trying to achieve) try using the FileServerUser that accepts 4 parameters (root and home).

var user = new FileServerUser(userName, userPassword, "/", "/user1");

...