How to write Batch Scripts

A batch file is a plaintext file or script file, which contains multiple commands to achieve a certain task. It contains a series of commands that is executed by a command line interpreter. Some basic commands of batch files:

A batch script can be used in process triggers in the Events panel of the CompleteFTP Manager, to check that the information of the events is saved in the created file in the script.

Referring to event information

CompleteFTP makes the details of the event (the file name, the user, the time, and so on) available to your batch script as environment variables. Reference them using cmd's delayed-expansion syntax, e.g. !FileName! and !LoginUserName!. CompleteFTP enables delayed expansion automatically when it sees a value referenced this way, so no extra setup is needed. The variable name is the macro name without the % signs; the date/time values are prefixed with Event (!EventDate!, !EventTime!, !EventDateAndTime!). The full list is on the Macros page, and the Manager's macro menu inserts the correct form for you.

Sample code

This script checks that the Move file event works properly with a Batch script type.

:: Create a BatchScript_Result.txt file in C:\Temp which contains information of the newly moved file
echo File "!FileName!" has been moved to another directory at !EventTime! > "C:\Temp\BatchScript_Result.txt"

Note: the older %FileName% / %Time% form is still supported for backward compatibility, but is not recommended for new scripts: values substituted that way have characters that are special to cmd replaced with underscores. Prefer the !FileName! form above, which delivers the value unchanged. See Using macro values safely.

Steps to apply the above script:

1. Go to the Process Triggers tab, and add a new process trigger for a Move file event.

2. Configure the process trigger as follows:

3. Input the above script with Batch script type, then Apply change.

4. From the FTP client, connect to the CompleteFTP server with user user1 and either move a file to another folder, or rename a file -> Ensure that the user is logged in successfully and the file is moved/renamed successfully.

5. Navigate to C:\Temp and ensure that there is a BatchScript_Result.txt file, which contains the information of the newly moved file.