In a previous article we’ve been talking about the new properties and methods introduced by Syncplify.me Server! v3 to improve the session object. One of such methods is Session.Terminate that basically instructs the FTP(S) or SFTP server to forcefully terminate the session as soon as the script execution ends.
In such post we have mentioned the addition of another useful function, often used in conjunction with Session.Terminate: the Blacklist function (which name is pretty self-explanatory). In this article we will explain how to use it.
First of all, let’s see the functions definition:
function Blacklist(const IPorNetwork: string; const AMinutes, AType: integer): boolean;
There are 3 parameters:
- IPorNetwork: the first parameter clearly should be the specific IP address (e.g.: 192.168.172.25) or the network/subnet (e.g.: 192.168.172.0/255.255.255.0) that you want to blacklist
- AMinutes: this is pretty intuitive too, it is the number of minutes you want the above IP address or network to be blacklisted for (unless you are permanently blacklisting it, see point #3 here below)
- AType: this parameter can be either ttTemporary or ttPermanent. If you want to temporarily blacklist the IP/network you will use ttTemporary and the IP/network will stay in the blacklist only for AMinutes minutes. Instead if you use ttPermanent the IP/network will be blacklisted forever (unless manually removed) and the AMinutes parameter will be ignored.
So, if for example we wanted to write a script that “kicks and bans” the client for half an hour if it tries to upload a JPEG file, we could do the following:
FExt := Lowercase(ExtractFileExt(ObjectName));
if (FExt = '.jpg') then
Blacklist(Session.ClientIP, 30, ttTemporary);
The above is just an example, of course, but it shows the simpliest way to use the Blacklist function in conjunction with Session.Terminate. Now you can write your own scripts to address your own particular cases.