Documentation forKiwi CatTools

Scripting Options

This pane allows you to specify VBscripts that are run before and/or after a TFTP session. To set scripting options:

  1. Go to Options > Setup.
  2. Select the TFTP Server tab.
  3. Select the Scripting Options.

Use the tick boxes to determine whether a script is run and enter the full path to the script in the appropriate text box.

Timing Issues 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.
Scripting Information

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 allows the TFTP session to continue.
  • Returning a value of False causes the TFTP session to abort.

For security reasons if the script can not be loaded or if the script fails then the TFTP session is aborted.

Scripting information session properties

You can access the following properties of the session:

Session.CreatTime

The time the session was started by the host.

Represented as the number of seconds from midnight 1/1/1970 UTC.

Session.FileName Name of the file to be written.
Session.FileSize Size of the file on the server for a 'Get' operation. This is zero for a 'Put' operation.
Session.Host IP address of the remote client represented as a long. The address is converted from an 8 digit hex value.
Session.Hosts

IP address of the remote client represented as a string. For example: 127.0.0.1

Session.Port TFTP Port on the remote client.
Session.TransferSize

The number of bytes transferred so far.

In the pre-session script, this is zero. In the post-session script, this is the whole file size.

Session.Type
  • Upload for a Put.
  • Download for a Get.

Example Scripts

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

Function Main(session)
	Main= False
	With session
		If .HostS = "192.168.1.60" Then
			.FileName = "NewFileName.txt"
		End If
	End With
	Main= True
End Function

Reject a file based on the time of day

Function Main(session)
Dim CreateHour
	Main= False
	With session
		'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
			Case 1,22,23,24
			'accept files created at any other time
			Main=False
			Case Else
			Main=True
		End Select
	End With
End Function

There is a known bug that occurs if a script is triggered in the pre-session event that renames the filename, such as .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.