Applies to: Syncplify.me Server! Version(s): 5.x
One of the methods exposed by the Session object is Session.Terminate that basically instructs the FTP(S) or SFTP server to forcefully terminate the session as soon as the script execution ends.
There is 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 definition of the function:
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:
var FExt: string; begin FExt := Lowercase(ExtractFileExt(ObjectName)); if (FExt = '.jpg') then begin Blacklist(Session.ClientIP, 30, ttTemporary); Session.Terminate; end; end.
The above is just an example, of course, but it shows the simplest way to use the Blacklist function in conjunction with Session. Terminate. Now you can write your own scripts to address your own particular cases.