Skip to content

The "Session" object

Almost every script run by Syncplify Server!’s event-handling subsystem exposes a built-in Session object. This object represents the current client session being served, and most script methods interact with it.

The Session object provides a standardized interface across all protocol handlers, ensuring consistency regardless of the protocol in use. Its structure is as follows:

ts
class Session {
  GetID(): string;
  GetUser(): User;
  GetUserID(): string;
  GetVirtualSite(): string;
  GetRemoteAddress(): string;
  GetClientVersion(): string;
  GetProtocol(): string;
  GetStartTime(): Date;
  GetLastActivity(): Date;
  BlockOperation(): void;
  AddCustomData(s: string): void;
  GetCustomData(idx: number): string;
  GetAllCustomData(): string[];
  AddQuestion(pos: number, q: string, a: string, echo: boolean): void;
  AddQuestionPassword(pos: number, q: string): void;
  AddQuestionTOTP(pos: number, q: string): void;
  AuthenticateUserFromScript(): void;
  GetAbsPath(): string;
  GetAbsTargetPath(): string;
  GetRelPath(): string;
  GetRelTargetPath(): string;
  RemoveFromListDir(value: string): void;
  GetLastCommand(): string;
  GetLastCommandTime(): Date;
  GetLastError(): string;
  GetLastErrorTime(): Date;
}

NOTE

The Session object is consistent across all supported protocols (SFTP, FTPS, FTP, etc.), so you can rely on its interface regardless of how clients connect.

Use the navigation menu on the left to access detailed documentation for each member function of the Session object.

WARNING

The Session object is always null (and cannot be used) in scripts run by event-handlers that fire before the client session is created, specifically: OnNewConnection and BeforeSendSoftwareID.

Example

Here's a short example that logs the session ID and username of the connected user. Typically, the OnAuthSuccess event-handler is the appropriate place to use this script.

ts
{
  if (Session) {
    var sid = Session.GetID();
    var uname = Session.GetUserID();
    Log('User ' + uname + ' connected with session ID ' + sid);
  } else {
    Log('Session object is not available.');
  }
}

TIP

The User object returned by Session.GetUser() provides detailed information about the authenticated user. See the User object documentation for details.

If your script is triggered by an event-handler that runs before authentication, Session.GetUser() will return null and should not be used. In these cases, Session.GetUserID() is safe to call—it will simply return an empty string if no user is authenticated.