JSS-to-.NET Bridge Extensions

JSS-to-.NET bridge extensions may be used to call into .NET from JSS, thus offering wide extensibility to the JSS platform. It might be used, for example, to wrap a simple .NET function, so that it may be used in JSS or as a bridge between JSS and a .NET API for a web-service.

A JSS-to-.NET bridge extension is a .NET assembly (usually a DLL) that contains a class, which extends the class EnterpriseDT.Net.FtpServer.Core.PlugIn and has one or more methods with the JavascriptInvokable attribute. The assembly can be developed in C#, VB.NET or any other .NET language. If you don't already have Visual Studio then you can use one of Microsoft's free Visual Studio Express or Community products.

Creating a JSS-to-.NET Bridge Extension

General instructions on building CompleteFTP extensions may be found here.

JSS-to-.NET bridge extension classes must extend EnterpriseDT.Net.FtpServer.Core.PlugIn. Each method that is to be exposed to JSS must have a JavascriptInvokable attribute. If the JavascriptInvokable attribute specifies a name, then this is the name by which the method must be called from JSS. If no name is specified, then the name of the .NET method is used.

Arguments may be passed to a method and values returned. Javascript numbers will be cast to .NET doubles; Javascript strings will be cast to .NET strings; Arrays will be cast to List<object>; and Javascript objects will be cast to Dictionary<string, object>.

Calling .NET methods from Javascript

Once a JSS-to-.NET Bridge has been added the methods it contains may be called using the following pattern:

PlugInName.methodName()

where PlugInName is the name of the plug-in set in the CompleteFTPManager and methodName is either the name of the method or the name specified by the JavascriptInvokable attribute if one is provided for the method.

Example

The following example implements methods that calculate hashes using two algorithms, MD5 and SHA1. Notice that the JavascriptInvokable attributes specify the names that should be used to call them from JSS, i.e. calculateMD5 and calculateSHA1.

using System;
using EnterpriseDT.Net.FtpServer.Http.Javascript;
using System.Web.Security;
using EnterpriseDT.Net.FtpServer.Core;

public class HashFunctions : PlugIn
{
	[JavascriptInvokable("calculateMD5")]
	public string CalcMD5(string s)
	{
		return FormsAuthentication.HashPasswordForStoringInConfigFile(s, "MD5");
	}

	[JavascriptInvokable("calculateSHA1")]
	public string CalcSHA1(string s)
	{
		return FormsAuthentication.HashPasswordForStoringInConfigFile(s, "SHA1");
	}
	public override void Dispose()
	{
	}

	public override void Initialize(IPlugInInfo info)
	{
	}
}

Add the extension as type ‘JSS-to-.NET Bridge’ in the Extensions panel in the Manager. Make sure that the name you use, only has letters and no spaces, .e.g‘HashFunctions'.

Once you’ve added the extension, you can use the class in a JSS upload process trigger like the following:

var ftp = new Ftp("Servername", "Username", "Password");
    ftp.connect();
    ftp.upload(event.virtualPath, event.fileName);
    ftp.close();
    console.log(HashFunctions.calculateMD5(event.virtualPath));

This should write the MD5 hash of the file-name to the log, each time a file is uploaded.