asyncFTP
Sends a file to an FTP server. If a callbackis provided, asyncFTP calls it when the operationis complete.
Note:As the file is transferred, a progress attributeis updated. You can add an ogscipt handlerto monitor changes to the attributeto show progress.
Syntax
ogscript.asyncFTP (host, port, username, password, destPath, destName, binary, sourceFilePath, callback);
Parameters
Parameter |
Type |
Required |
Description |
host |
String |
Yes |
The host name of the destination computer. |
port |
Integer |
Yes |
The port number to which the data is to be sent. |
username |
String |
Yes |
The username required to log onto the destination computer. |
password |
String |
Yes |
The password required to log onto the destination computer. |
destPath |
String |
No |
The directory path where the data is to be saved on the destination computer. |
destName |
String |
No |
The name of the destination file. Can be used to rename the existing file. If a file with the same name exists in the destination path, that file is overwritten. |
binary |
Boolean |
Yes |
Specifies the transfer mode. When true, binary transfer is used. When false, ASCII transfer is used. |
sourceFilePath |
String |
Yes |
The directory path to the source file. The path can be absolute or relative. |
callback |
function reference |
No |
The callback is called when the operation is complete, whether or not the operation is successful. |
Returns
N/A
Example 1
The following exampleis a task. It uses variable to populate the parameters of the asyncFTP function. It also includesa callback to indicate successor failure of the transfer.
<tasktasktype="ogscript">function callback(success, sourceFilePath, exception)
{
if (success)
{
ogscript.rename('label.bytes', 'SUCCESS!');
}
else
{
ogscript.rename('label.bytes', 'FAIL!');
}
}
ogscript.rename('label.bytes', 'TRYINGTO SEND FILE'); var host = params.getStrValue('params.host', 0);
var port = params.getValue('params.port', 0);
var user = params.getStrValue('params.username', 0);
var password= params.getStrValue('params.password', 0); var file = params.getStrValue('params.file', 0);
var destPath= params.getStrValue('params.destpath', 0); var destFileNameOverride = null;
var isBinary= true;
ogscript.asyncFTP(host, port, user, password, destPath,destFileNameOverride, isBinary, file, callback);
ogscript.rename('label.bytes', 'Waiting...');
</task>
Example 2
The following is an exampleof an ogscript handler for monitoring and reporting the progress of the transfer.
<ogscript attribute="com.rossvideo.ftp.event" handles="attributechange">
var progressEvent = event.getNewValue();
if (progressEvent == null)
{
ogscript.debug('No progress');
}
else
{
ogscript.rename('label.bytes', (progressEvent.getTotalBytesTransferred() / 1024) + 'kb');
}
</ogscript>