Quantcast
Channel: Syncplify.me
Viewing all articles
Browse latest Browse all 144

Scripting lesson: using scripting and session info

$
0
0

This articles shows how to use scripting, event-handling and session information from within Syncplify.me Server! For the sake of this example we will only log such information in the log file, but in real-life production scenarios you can use these info as you wish (for example you may want to send them via email to someone, or even make decisions based upon them).

Let’s start by preparing the script that – as we said – will log some info in your Syncplify.me Server!’s log file:

begin
  AddToLog('Script being run: '+ScriptName+' (ID: '+ScriptID+')');
  AddToLog('Triggered by event: '+EventHandler+' (Priority: '+IntToStr(HandlerPriority)+')');
  AddToLog('Virtual object affected: '+VirtualObjectName);
  AddToLog('Physical object (available only for "Disk*" VFSs): '+ObjectName);
  AddToLog('Client connected from: '+Session.ClientIP);
  AddToLog('Client software: '+Session.ClientSoftware);
  AddToLog('User authenticated as: '+Session.ReqUsername);
  AddToLog('Protocol: '+Session.Proto);
  AddToLog('Files uploaded so far during this session: '+IntToStr(Session.FilesUp)+' (KB: '+FloatToStr(Session.KBUp)+')');
  AddToLog('Files downloaded so far during this session: '+IntToStr(Session.FilesDown)+' (KB: '+FloatToStr(Session.KBDown)+')');
  AddToLog('Last client command: '+Session.LastCommand+' ('+FloatToStr(now-Session.LastCommandTS*24*60)+' minutes ago)');
end.

We save the above script with the following name/description: “Log several client and connection info”.

Then we add an event-handler to trigger the execution of the script. Since the script contain references to file-transfer-related variables (VirtualObjectName and ObjectName) it seems obvious to trigger its execution upon occurrence of a file-transfer-related event. For the sake of this example we have chosen the AfterFileUpload event, which occurs every time a file is successfully uploaded by a client onto the server.

wintfexample2

Once the event-handler is created, we simply Save the configuration, and run an FTP/SFTP client to test if it works as expected. For the sake of this example we run FileZilla and upload one file. Right after the upload, we open the log file with a text editor, and here’s what we find inside:

#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Script being run: Log several client and connection info (ID: K6VH4MAMMDBETNW27335J57YNY)
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Triggered by event: AfterFileUpload (Priority: 10)
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Virtual object affected: /Arrays.txt
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Physical object (available only for "Disk*" VFSs): C:\TestRoot\test\Arrays.txt
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Client connected from: 127.0.0.1
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Client software: PuTTY_Local:_Mar_16_2016_11:17:04
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] User authenticated as: test
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Protocol: SFTPv3
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Files uploaded so far during this session: 1 (KB: 471.4716796875)
#Remark: 2016-04-17 20.39.21 [AOBEJVIHQWE3GAB3VIZSI4DQQ] Files downloaded so far during this session: 0 (KB: 3.7314453125)

Feel free to modify this example to suit your needs.


Viewing all articles
Browse latest Browse all 144

Trending Articles