0 votes
by (240 points)

I have a Rebex FileServer with an SFTP binding and an implementation of a ReadWriteFileSystemProvider. When a user performs certain operations on the SFTP server (file create/modify/delete/etc), I need to process metadata about that operation, which must include information about the user.

I cannot find any way to extract the user from the ReadWriteFileSystemProvider or from the FileSystemNotifier events, though. I don't particularly care which one gives me the user (I can make what I need to do work with either one). I'm open to alternatives if there's another path that gets me what I need.

How can I get the FileServerUser from a ReadWriteFileSystemProvider method or a FileSystemNotifier event?

Applies to: File Server

1 Answer

0 votes
by (73.5k points)

It is very easy. Just use: ServerSession.Current.User

by (240 points)
Where do I get an instance of `ServerSession` from?
by (5.3k points)
edited by
Hi asgallant,
thanks for the question.
Despite the tight integration between both components and intended similarities in the API, FileServer and Virtual FileSystem are two independent components.
I think that you are looking for this.

1) Add the reference to the Rebex.FileServer assembly.
2) Add the using directive - using Rebex.Net.Servers.
3) Use the ServerSession.Current static property.

https://www.rebex.net/doc/api/Rebex.Net.Servers.ServerSession.Current.html

 private static void MyFilterDownloadFiles(object sender, GetChildrenEventArgs e)
 {

// obtain the current session.

    var session = ServerSession.Current;

...

}

You can obtain a current session from every event handler in the FileSystemNotifier and from methods in the Read(Write)FileSystemProvider as well. From the Virtual File System component point of view ServerSession.Current is an "ambient context"  (when the Virtual File System serves as a constitutive part of the FileServer).
by (240 points)
Thanks, I'll give that a try.
...