Applies to: Server!
Version(s): 4.x - 5.x

As many of you know, the FTP protocol (and therefore also both its encrypted versions FTPS and FTPES) feature a very simple way for clients to send custom commands to the server: the SITE command (RFC 959).

Some servers implement a fixed set of site-specific commands through it, but Server! goes beyond that and gives the server’s administrator total control over the SITE command handler behavior and response.

Thanks to an ( OnCustomSITECommand) event intercepted by the event-handling subsystem, it is now possible to run an arbitrary number of scripts upon receipt of a SITE command; such scripts have access to the parameters that were passed in the SITE command itself and can execute custom code as well as set the response code and message.


Look at the following (trivial) example:

  if Session.CurURIStem = 'hello' then
    Session.SiteCmd.ReplyCode := 200;
    Session.SiteCmd.ReplyMsg := 'Hello there!';
    Session.AllowNextOperation := true;
    Session.AllowNextOperation := false;

The above example script checks the parameter (which regardless of the command is always accessible through the Session.CurURIStem property) sent along with the SITE command. If the parameter is “hello” then it sets a custom reply and allows the execution of the site command (which simply returns the custom reply, nothing else). Instead, if the parameter is not “hello” is just disallows the execution of the SITE command, which will return an error code to the client.

Since the SITE command can be called by the client asynchronously, and at any stage of the FTP session (after login), then you now have a way to send commands to the server that will trigger the execution of your custom scripts at any time.