CompleteFTP is highly customizable allowing users to extend its inbuilt functionality using JSS, as well as .NET assemblies, batch scripts, Powershell scripts and executables.
JSS (Javascript Server-Side) is the name given to CompleteFTP's scripting environment. It includes a Javascript language interpreter and an API for integrating with CompleteFTP as well as performing common tasks.
Applications of JSS
JSS may be used to implement:
-
Process triggers that are executed when one or more specified events occur within CompleteFTP, such as a user logging in, a client uploading a file or a scheduled timer ticking over.
-
IP filter extensions facilitate the addition of custom rules for blocking connections from specified IP addresses (e.g. IP addresses from particular countries).
-
Authentication extensions allowing CompleteFTP to authenticate via a source other than those that are already built-in (i.e. internal users, Windows users, databases and remote FTP/SFTP servers).
-
File-system extensions which implement custom file systems that may, for example, store files in storage other than file-systems, e.g. databases.
-
Custom-command extensions contain user-defined functions that may be invoked by clients via FTP (via the SITE command), SFTP (via SSH_FXP_EXTENDED), SSH (as terminal commands) and HTTP/S (via GET or POST).
-
Web applications that may be accessed by regular users just like any other web application. EnterpriseDT's own customer portal, edtConnect, is a JSS web-app that's hosted on CompleteFTP. It accepts electronic payments and manages licenses for many thousands of users.
JSS API Overview
The JSS API is organized into three sections visible in the sidebar:
Globals
Global objects (also called services) are available in all JSS scripts without requiring instantiation. Their names start with a lower-case letter:
- console - logging to CompleteFTP logs
- event - event information in process triggers
- http - HTTP client for web requests
- mail - sending emails
- request - HTTP request data in web applications
- response - HTTP response in web applications
- system - system information, configuration access, and utilities
- templater - template rendering
Objects
Objects are classes that provide features such as FTP/SFTP clients, virtual file-system access, and database access. Their names begin with an upper-case letter:
- File - virtual file system access
- Ftp - FTP/SFTP client
- JsonDB - JSON document database
- DatabaseSync - SQL database access
- ShareAPI - file sharing functionality
Global Functions
Global functions available in all scripts:
- include - include and execute another script file
- publish - expose functions for RPC access
- atob - decode base64 string
- btoa - encode string to base64
- encodeHTML - HTML entity encoding
- md5 - MD5 hash function
- sleep - pause script execution
Configuration APIs
CompleteFTP provides two configuration APIs for reading and modifying server settings
programmatically. Changes are not applied until applyChanges() is called.
Config2 (Version 2)
Extended configuration API with additional features. Access via system.getConfig2():
var config = system.getConfig2();
var site = config.sites.get("Default");
site.welcomeMessage = "Welcome to our server";
config.applyChanges();
Config2 classes use the Config2_ prefix:
- Config2 - entry point
- Config2_UserManager, Config2_User - user management
- Config2_GroupManager, Config2_Group - group management
- Config2_FolderManager, Config2_Folder - virtual folder management
- Config2_SiteManager, Config2_Site - site management
- Config2_ServerManager, Config2_Server - server management
- Config2_WebAppManager, Config2_WebApp - web application management
- Config2_EmailNotificationManager - email notifications
- Config2_ProcessTriggerManager - process triggers
- Config2_AuthenticatorManager - authentication providers
- Config2_LicenseManager - license management
- Config2_Monitoring - monitoring configuration
Config1 (Version 1) - Legacy
The original configuration API. Access via system.getConfig():
var config = system.getConfig();
var user = config.users.get("john");
user.email = "john@example.com";
config.applyChanges();
Config1 classes use the Config1_ prefix:
- Config1 - entry point
- Config1_UserManager, Config1_User - user management
- Config1_GroupManager, Config1_Group - group management
- Config1_FolderManager, Config1_Folder - virtual folder management
- Config1_Site - site configuration
- Config1_IPFilter, Config1_IPFilterRule - IP filtering
Integrating with .NET
JSS offers two methods of integrating with .NET:
-
Inline use of .NET libraries - in JSS process triggers and all types of JSS extensions, .NET classes may be instantiated directly from JSS, for example,
new System.Text.StringBuilder()will instantiate the .NET class,StringBuilder. This objects properties and methods may be accessed in the same way as those of native Javascript objects. The names of classes must be fully qualified. This usage is disallowed in web apps for security reasons. -
JSS-to-.NET bridge extensions - any .NET class that has a public null constructor may be registered as a JSS-to-.NET extension. Once this has been done, an instance of it will be created when a JSS script is invoked by CompleteFTP. The name of this instance will be the same as the registered name of the extension. So if, for example, a class called
MyNamespace.MyClasscontaining a method calledMyMethodis registered in CompleteFTP Manager with the namemyStuff, then the method may be called from JSS using the expressionmyStuff.MyMethod(). The location of the assembly containing this class is specified upon registration.
ECMAScript Compliance
JSS uses the Jint JavaScript interpreter, which provides extensive ECMAScript support including ES6 (ES2015) and later features up through ES2023.
Supported features include:
- Arrow functions, classes, and modules
- Template literals and destructuring
- Promises and async/await
- let/const declarations and block scoping
- Spread operator and rest parameters
- Map, Set, WeakMap, WeakSet collections
- Symbol and iterators
- Array methods (find, includes, flat, flatMap, etc.)
- Object methods (entries, values, fromEntries, etc.)
- Optional chaining (?.) and nullish coalescing (??)
- String methods (padStart, padEnd, trimStart, trimEnd, etc.)
Note: Generator functions are not currently supported.