Site-Command Extensions

A site-command extension is a .NET assembly (usually a DLL) that contains a class that extends the class EnterpriseDT.Net.FtpServer.Core.SiteCommands. 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 products (e.g. Visual C# or Visual Basic).

Creating a site-command extension

General instructions on building CompleteFTP extensions may be found here. In addition to the registration steps described in the general instructions, permissions must also be granted for users and/or groups to access a site-command extension, otherwise no users will be able to invoke the commands.

Permissions for site-command extensions are managed in the Site-Command Permissions tab of the Extensions panel in CompleteFTP Manager. The commands in a site-command extension may be executed by a user that's been directly given or is a member of a group that has been given permission to do so.

Commands are added to a site-command extension simply by adding methods. By default the name of the method becomes the name of the command. If a SiteCommandName attribute is defined then that becomes the name of the command. All names are case-insensitive. The arguments of the method become the arguments of the command. All the arguments must be strings. Site-commands may return one or more lines of text.

The way in which a command is executed by a client depends on the protocol. In FTP site commands must be preceded by SITE. For example, the inbuilt change password command may be invoked as follows:

ftp> site cpwd mypassword
200-CPWD successful
200 SITE command successful.
ftp>

Note that if you're using Microsoft ftp.exe then you need to enter "quote site mypassword".

Example

The following example implements the ubiquitous Hello World example as a site-command:

using EnterpriseDT.Net.FtpServer.Core;

namespace SampleExtensions
{
    public class HelloWorldSiteCommands : SiteCommands
    {
        public string HelloWorld()
        {
            return "Hello world!";
        }

        [SiteCommandName("HelloWorld2")]
        public string HelloWorldWithArgs(string argument1, string argument2)
        {
            return "Hello world!\n" + argument1 + "\n" + argument2;
        }
    }
}

The first method has no arguments and defines no SiteCommandName attribute. This means that it must be called by its full name, "HelloWorld" (case is ignored). The second method has two arguments so two arguments must be entered when the command is executed by the client. This method also defines a command-name, so that name, "HelloWorld2", must be used when the command is executed by the client. In addition, it illustrates that multiple lines may be included in a reply.