Secure FTP Server/SFTP Server

18 Route 6A, Sandwich, MA 02563 USA

70 Bridle Close, Paignton, Devon, TQ4 7ST UK

How do I create a command that will work with a FileCOPA Event

FileCOPA contains an Event System from which you can do things like send an email, add to a custom log file, send a message, etc. One of the options is to run a command. This can be very powerful, but can also be tricky to get working correctly.

The FileCOPA FTP Server runs as a system service. This means that it has no Graphical Output. Therefore any command you create that is executed on an event must also have no graphical output. This can limit the languages that you can use as many languages create a Window by default. If you attempt to run a command that has graphical output then it will fail to start.

A good solution to this problem is to use the PHP Command Line Interface to run a PHP script. As PHP will produce no output (unless your script specifically tells it to) then it will work just fine from a FileCOPA Event.

Here is an example script that will fire on the On Uploaded File event and rename the file that was uploaded with the current date and time. This assumes you already have PHP installed on your system.

Create a PHP script with the following content and store it on your c: drive as c:\scripts\rename.php

<?php

        $fileinfo=pathinfo($argv[1]);

        $datestr =date("ymdHis");

        $newfile =$fileinfo["dirname"] . "\\" . $datestr . "." . $fileinfo["extension"];

 

        rename($argv[1],$newfile);

?>

In the On Uploaded File event go to the command tab. Enable the event. Set the Command to be the location of your php.exe file, eg c:\Program Files\PHP\php.exe

Set the parameters to c:\scripts\rename.php <<FULLFILEPATH>>