SFTP Server: How to prevent creation of subdirectories

0 votes
asked Nov 3, 2017 by Matthias H (160 points)
edited Nov 3, 2017 by Matthias H

I want to prevent the users from crating subdirectories on my sftp server.

I tried PathAccessAuthorization, but I have no idea how I can find out whether the user is trying to create a file (allowed) or a folder (forbidden).

1 Answer

+1 vote
answered Nov 3, 2017 by renestein (1,190 points)
edited Nov 3, 2017 by renestein
 
Best answer

Hi Matthias,
welcome to the Rebex forum. You can use for this scenario our new API.

1) Create LocalFileSystemProvider

    private LocalFileSystemProvider createFileSystem()
    {
        var localFileSystem = new LocalFileSystemProvider(@"<<your path>>");
        //subscribe to CreatePreview event
        localFileSystem.GetFileSystemNotifier().CreatePreview += (sender, args) =>
        {
            if (args.Node.IsDirectory)
            {
                args.CancelOperation();
            }
        };

        return localFileSystem;
    }

2) Use FileSystemProvider.

 _fileSystem = createFileSystem();
 _user01 = new FileServerUser(_username, _password, _userVirtualRoot);
_server.Users.Add(_user01);
_user01.SetFileSystem(_fileSystem);

Please note that LocalFileSystemProvider is a part of the new file system API (https://www.rebex.net/file-server/features/virtual-file-systems.aspx), which is available since Version 2017 R4 (https://www.rebex.net/total-pack/history.aspx#2017R4)

...