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.
??
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 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.) |
Session.Hosts | 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. |
Session.TransferSize | 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. |
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
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.
??