Skip to content

CtxVFSName()

ts
function CtxVFSName(): string;

Returns the name of the Virtual File System (VFS) associated with the event that triggered this script. Note that this is the VFS name, not its ID. Returns an empty string "" for events that fire before any VFS has been selected in the session (e.g. OnNewConnection, BeforeSendSoftwareID, and all authentication events).

Why this function exists, and why it matters

IMPORTANT

Always use CtxVFSName() when your script needs to know which VFS the triggering event refers to. Never rely on Session.GetCurrentVFSName() for this purpose.

Syncplify Server! runs event-handler scripts asynchronously and concurrently. By the time a script begins executing, or at any point during its execution, the session may have already switched to a different VFS, because the client has kept working. Session.GetCurrentVFSName() reflects the session's live, current state, not the VFS that was active when the event fired.

CtxVFSName() is different. The VFS name is captured at the moment the event fires and frozen into the script's execution context. It never changes while the script runs, regardless of what the client does in the background. This makes it the only reliable way to reference the VFS involved in the triggering event.

Return value

ScenarioReturn value
Event fired while a VFS is attached to the sessionThe VFS name, e.g. MainStorage
Event fired before any VFS selection (connection, authentication, ...)"" (empty string)

Example

ts
{
  var vfsName = CtxVFSName();
  if (vfsName === "") {
    Log("This event occurred before any VFS was selected.");
    Exit();
  }
  Log("Event refers to VFS: " + vfsName);

  if (vfsName === "Quarantine") {
    Log("File activity detected on the quarantine VFS.");
  }
}

WARNING

CtxVFSName() is not available prior to v8.0.4. Please upgrade to v8.0.4 or newer to use this function.

See also

  • EventCtx(): returns the whole event context (path, target path, VFS name) as a single object
  • CtxRelPath(): the path of the file that triggered the event
  • CtxRelTargetPath(): the target path of a rename or move operation
  • EventHandler(): returns the name of the event that triggered this script