Skip to content

The "VFS" object

The VirtualFileSystem object provides secure, virtualized access to Syncplify Server!'s Virtual File System (VFS) subsystem. Use it to work with the user's current VFS or to create temporary access to other locations (local directories, S3 buckets, Azure Blob Storage, Google Cloud Storage, or remote SFTP servers) for your script's tasks.

NOTE

Temporary VFS objects are ephemeral: they exist only for the duration of the script and do not persist after the script ends.

Response Types

All methods return one of the response types documented here:

TypeDescription
respBaseBasic result: success/failure, error info
respSizeFile/directory size
respStatFile/directory metadata
respDirDirectory listing
respReadStringFile read result (string/hex)
respReadBytesFile read result (byte array)

Class Methods

The methods of VirtualFileSystem are grouped as follows:

  • Filesystem Operations: Create, remove, rename, and inspect files/directories.
  • File Read/Write: Read and write file contents in various formats.
  • Import/Export: Move files between the VFS and external locations or other VFS objects.
ts
class VirtualFileSystem {
  // Filesystem operations
  Stat(path: string): respStat;
  Lstat(path: string): respStat;
  ReadDir(path: string, sortBy: string, sortDir: string): respDir;
  Mkdir(path: string): respBase;
  MkdirAll(path: string): respBase;
  Rmdir(path: string): respBase;
  Rename(source: string, target: string): respBase;
  Remove(filePath: string): respBase;
  RemoveAll(path: string): respBase;
  TreeSize(path: string): respSize;
  Symlink(path: string, linkFile: string): respBase;
  Chown(path: string, uid: number, gid: number): respBase;
  Chmod(path: string, mode: number): respBase;
  Chtimes(path: string, atime: number, mtime: number): respBase;
  Truncate(filePath: string, size: number): respBase;
  // File read/write
  ReadFileAsText(filePath: string, length: number, offset: number, whence: number): respReadString;
  ReadFileAsHex(filePath: string, length: number, offset: number, whence: number): respReadString;
  ReadFileAsBytes(filePath: string, length: number, offset: number, whence: number): respReadBytes;
  WriteFileAsText(filePath: string, data: string, offset: number, whence: number): respBase;
  WriteFileAsHex(filePath: string, data: string, offset: number, whence: number): respBase;
  WriteFileAsBytes(filePath: string, data: Uint8Array, offset: number, whence: number): respBase;
  // Import/export
  ImportFile(localFilePath: string, targetVfsFilePath: string): respBase;
  ExportFile(vfsFilePath: string, localFilePath: string): respBase;
  CopyToVFS(localFile: string, targetVfs: VirtualFileSystem, targetVfsFilePath: string): respBase;
  MoveToVFS(localFile: string, targetVfs: VirtualFileSystem, targetVfsFilePath: string): respBase;
}

TIP

Use GetCurrentVFS() to access the user's current VFS after login. Use new VirtualFS(...) to create a temporary VFS for other locations or before login.

Using VFS in Event Handlers

You can create a temporary VFS object in any event-handler:

ts
var vfs = new VirtualFS(VfsTypeDisk, "/var/Uploads"); // or C:\\Var\\Uploads in Windows
if (vfs != null) {
  // Use the vfs object here
  var stat = vfs.Stat("/var/Uploads/test.txt");
  if (!stat.success) {
    // Handle error
    Log("Stat failed: " + stat.error);
  }
}

After a user has logged in and accessed their Home-VFS, you can obtain their current VFS:

ts
var vfs = GetCurrentVFS();
if (vfs != null) {
  // Use the vfs object here
  var dir = vfs.ReadDir("/", "name", "asc");
  if (!dir.success) {
    // Handle error
    Log("ReadDir failed: " + dir.error);
  }
}