To set scripting options, choose Options >??Setup > TFTP Server >??Scripting Options.
This pane allows you to specify vbscripts that will be run before and/or after a TFTP session.
Use the tick boxes to determine whether a script will be run and enter the full path to the script in the appropriate text box.
It's important to note that you only have 1 second to get everything done in the pre-session external script and return a value otherwise the TFTP session times out, and retries.
Your script must start with Function Main(session) where session is the TFTP session being passed in.
If the script is successful it should return a value of True which will allow the TFTP session to continue.
Returning a value of False will cause the TFTP session to abort.
For security reasons if the script can not be loaded or if the script fails then the TFTP session will be aborted.
You can access the following properties of the session:
|Session.CreatTime||The time the session was started by the host. (Actually represented as the number of seconds from midnight 1/1/1970 UTC).|
|Session.FileName||The name of the file to be written.|
|Session.FileSize||The size of the file on the server for a'Get' operation. (Will be zero fo a 'Put' operation.)|
|Session.Host||The IP address of the remote client represented as a long. (Converted from an 8 digit hex value.)|
The IP address of the remote client represented as a string. i.e. 127.0.0.1.
|Session.Port||The TFTP Port on the remote client.|
The number of bytes transferred so far.
Note: in the pre-session script this will be zero and in the post session script this should be the the whole file file size.
Upload for a Put. Download for a Get.
The script below checks the host address of the remote client issuing a 'Put'.
If it matches a certain address then the filename is changed.
Rename of the file based on host address:
If .HostS = "192.168.1.60" Then
.FileName = "NewFileName.txt"
Reject a file based on the time of day:
'convert the create time from the unix format to the current time
CreateHour = DateAdd("s", session.CreateTime, DateSerial(1970, 1, 1))
'convert to 24 hour format
CreateHour = FormatDateTime(CreateHour, vbShortTime)
'seperate out the hour value only
CreateHour = DatePart("h", currentTime)
Select Case CreateHour
'reject files created two hours either side of midnight
'accept files created at any other time
Note: At the moment there is a bug where if a script is triggered in the pre-session event that renames the filename e.g.. .FileName = "NewTestFileName.txt" The file is put into the TFTP folder with the filename correctly changed to NewTestFileName.txt but the existing 'Test.txt' file in the TFTP folder is deleted.