Administration with JSS scripts
(requires Enterprise MFT)

CompleteFTP's configuration can be modified using Javascript (i.e. JSS). All administration-related tasks involve the Config object returned by the system.getConfig() function.

There are several ways to execute such scripts:

  1. Interactively in the SSH terminal
  2. JSS script files piped to CompleteFTP via SSH
  3. JSS custom commands executed via SSH
  4. JSS web apps used interactively through a browser

These will be detailed below.

1. Interactively entering JSS configuration commands

  1. Make sure that SSH terminal is enabled for the Admin site
  2. Make sure that SSH terminal is enabled for the admin user
  3. Select JSS for the SSH terminal shell setting for the admin user (under the Scripting and Shells category)
  4. Install an SSH client such as OpenSSH (e.g. in the Windows Subsystem for Linux) or plink
  5. Connect to port 14983 as the admin user. If a public key-pair has been set up for the admin user then no password will be required, otherwise you will be prompted for the password.
  6. Enter the JSS statements on line at a time.
    For example, the following adds a user via OpenSSH run on Windows Subsystem for Linux using a public key for authentication:
    john@Warp:~/tmp$ ssh admin@localhost -p 14983
    admin@myserver:/Admin> var userName = "testuser";
    admin@myserver:/Admin> var password = "password";
    admin@myserver:/Admin> var homePath = "C:\\Temp";
    admin@myserver:/Admin> var config = system.getConfig();
    IMPORTANT!  Changes to the config will not be saved until applyChanges() is called.
    admin@myserver:/Admin> var newFolder = config.folders.add("/Home/" + userName, "windows", homePath);
    admin@myserver:/Admin> var newUser = config.users.add();
    admin@myserver:/Admin> newUser.userName = userName;
    admin@myserver:/Admin> newUser.password = password;
    admin@myserver:/Admin> newUser.siteMapping[0].homeFolder = newFolder.fullPath;
    admin@myserver:/Admin> config.applyChanges();

2. Executing JSS script files via SSH

After repeating steps 1 to 4 from section:

  1. Create a text file called adduser.jss containing the required JSS script
    For example, the following script adds a user:
    var userName = "testuser";
    var password = "password";
    var homePath = "C:\\Temp";
    var config = system.getConfig();
    IMPORTANT!  Changes to the config will not be saved until applyChanges() is called.
    var newFolder = config.folders.add("/Home/" + userName, "windows", homePath);
    var newUser = config.users.add();
    newUser.userName = userName;
    newUser.password = password;
    newUser.siteMapping[0].homeFolder = newFolder.fullPath;
    config.applyChanges();
    Note that all the constructs of EC3-level Javascript may be used.
  2. Execute the script as follows:
    john@Warp:~/tmp$ ssh admin@localhost -p 14983 < adduser.jss

3. Creating JSS custom commands for administration

  1. Open CompleteFTP Manager
  2. Select the Extensions panel
  3. Click Add extension → JSS (Javascript) extension → Custom commands
  4. Enter a Javascript function that performs the administrive task.
    For example, the following function adds a user with a given user-name, password, and Windows home directory:
    function CustomAddUser(userName, password, homePath) {
    	// get configuration
    	var config = system.getConfig();
    
    	// create the home folder
    	var newFolder = config.folders.add("/Home/" + userName, "windows", homePath);
    
    	// create a new user
    	var newUser = config.users.add();
    	newUser.userName = userName;
    	newUser.password = password;
    	newUser.siteMapping[0].homeFolder = newFolder.fullPath;
    
    	// apply the changes
    	config.applyChanges();
    }
  5. Install an SSH client (it's not necessary to set JSS as the SSH terminal shell)
  6. Execute the custom commands as follows:
    john@Warp:~/tmp$ ssh admin@localhost -p 14983 "CustomAddUser testuser password C:\\Temp"

4. Developing custom administration web-apps (Adminlets)

For information on developing 'adminlets', please refer to the EnterpriseDT repository on GitHub.