Home > Features > Transfer Queue Item Scripting
Article 2632
Transfer Queue Item Scripting
A script can be assigned to a transfer queue item which will be loaded right before the transfer queue item is processed. The transfer queue fires several events which can be handled by event handlers within the script. An event handler has access to the transfer queue operation object and indirectly - through this object - to the complete transfer queue facility.
Scripts assigned to individual transfer queue items make most sense when the same transfer queue item is processed multiple times. For example when it contains a trigger with a recurring schedule.
Objects exposed in the global scope:
The following events are sent from the TransferQueueOperation object:
For the complete reference please refer to the documentation included in the SmartFTP SDK1.
In the this tutorial we demonstrate how to use a script to transfer a file or folder to a different destination each time the item is processed. The idea is to implement a custom operation which does the following:
Let's start with the skeleton of the script:
VBScript
ScriptHost.Echo "Load" Sub TransferQueueOperation_OnBegin() ScriptHost.Echo "OnBegin" End Sub Sub TransferQueueOperation_OnRun() ScriptHost.Echo "OnRun" End Sub Sub TransferQueueOperation_OnEnd() ScriptHost.Echo "OnEnd" End Sub
JavaScript
ScriptHost.Echo("Load");
function TransferQueueOperation::OnBegin()
{
ScriptHost.Echo("OnBegin");
}
function TransferQueueOperation::OnRun()
{
ScriptHost.Echo("OnRun");
}
function TransferQueueOperation::OnEnd()
{
ScriptHost.Echo("OnEnd");
}
We choose to implement the logic for the custom operation in the OnRun() event handler.
VBScript
Sub TransferQueueOperation_OnRun() 'ScriptHost.Echo "OnRun" '// Create new transfer queue item based on this item Dim newItem Set newItem = TransferQueueOperation.CreateItem() '// copy its properties Dim item Set item = TransferQueueOperation.TransferQueueItem newItem.Type = item.Type newItem.Size = item.Size newItem.Operation = item.Operation newItem.SizeUnit = item.SizeUnit newItem.Source = item.Source.Clone() newItem.Destination = item.Destination.Clone() '// now change the destination path '// format the date/time "YYYYMMDD 'T' HHMMSS" Dim date date = CStr(Year(Now())) & CStr(prefixWithZero(Month(Now()))) & CStr(prefixWithZero(Day(Now()))) Dim time time = CStr(prefixWithZero(Hour(Now()))) & CStr(prefixWithZero(Minute(Now()))) & CStr(prefixWithZero(Second(Now()))) Dim suffix suffix = date & "T" & time newItem.Destination.Path = newItem.Destination.Path & suffix '// ScriptHost.Echo newItem.Destination.Path '// add the new item using the AddItem helper TransferQueueOperation.AddItem(newItem) '// return success. This prevents the operation to continue any further TransferQueueOperation.Result = sfTransferQueueOperationResultSuccess End Sub
JavaScript
function TransferQueueOperation::OnRun()
{
//ScriptHost.Echo("OnRun");
// Create new transfer queue item based on this item
var newItem = TransferQueueOperation.CreateItem();
// copy its properties
var item = TransferQueueOperation.TransferQueueItem;
newItem.Type = item.Type;
newItem.Size = item.Size;
newItem.Operation = item.Operation;
newItem.SizeUnit = item.SizeUnit;
newItem.Source = item.Source.Clone();
newItem.Destination = item.Destination.Clone();
// now change the destination path
// format the date/time "YYYYMMDD HHMMSS"
var now = new Date();
var date = now.getFullYear().toString() + prefixWithZero(now.getMonth() + 1).toString() + prefixWithZero(now.getDate()).toString();
var time = prefixWithZero(now.getHours()).toString() + prefixWithZero(now.getMinutes()).toString() + prefixWithZero(now.getSeconds()).toString();
var suffix = date + "T" + time;
newItem.Destination.Path = newItem.Destination.Path + suffix;
// ScriptHost.Echo newItem.Destination.Path;
// add the new item using the AddItem helper
TransferQueueOperation.AddItem(newItem);
// return success. This prevents the operation to continue any further
TransferQueueOperation.Result = sfTransferQueueOperationResultSuccess;
}
For the complete scripts please see the SmartFTP SDK1.
Keywords
script, queue