Has anyone an idea how to call the 'FTP Receive' based on the previously received an XML file with path to the file I want to download?
Thanks in advance
Aleksander
How to call 'FTP receive'
How to call 'FTP receive'
Aleksander
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Re: How to call 'FTP receive'
The "FTP Receive" configurator does not accept incoming connections. You will have to call a separate FTP program using "Execute Command" or a script.
Re: How to call 'FTP receive'
Thanks Dwight,
What do you mean by script. From what I know Java Script does not support FTP protocol.
Can you give a hint?
What do you mean by script. From what I know Java Script does not support FTP protocol.
Can you give a hint?
Aleksander
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Re: How to call 'FTP receive'
Code: Select all
// FTPget - get file from FTP server
//
// Developed by Dwight Kelly <dkelly@apago.com>
// Copyright 2015 - Apago, Inc. -- All rights reserved
//
// Switch logging & output levels
const cLogAssert = -2;
const cLogDebug = -1;
const cLogInfo = 1;
const cLogWarning = 2;
const cLogError = 3;
const cLogProgress = 5;
function jobArrived( s : Switch, job : Job )
{
var theServer = s.getPropertyValue("server");
if (theServer.length == 0) {
job.fail("FTPget: No Server specified!");
return;
}
var thePath = s.getPropertyValue("path");
if (thePath.length == 0) {
job.fail("FTPget: No path specified!");
return;
}
var username = s.getPropertyValue("username");
var password = s.getPropertyValue("password");
var f = new File(thePath);
var newFileName = job.createPathWithName(f.name, false);
delete f;
var argc = 0;
var args = new Array();
args[argc++] = "ftp";
args[argc++] = "ftp://"+username+":"+password+"@"+theServer+"/"+thePath;
args[argc++] = "-o"; args[argc++] = newFileName;
var exitStatus = Process.execute(args);
if (exitStatus == 0) {
job.sendToData(3, newFileName);
} else {
job.log(cLogError, "FTPget: download failed, " + Process.stdout);
job.sendToData(3, job.getPath());
}
}
Re: How to call 'FTP receive'
Thanks Dwight,
everything seems ok but I get the error "Error in line 22 of the script: Error. Trying to access undefined member 'length'".
Error relates to "thePath" where I write the name of folder on the server.
When I replace real data to model "ftp://username:password@theServer/thePath" and I put it in browser, everything is OK.
I do not know what I'm doing wrong?
everything seems ok but I get the error "Error in line 22 of the script: Error. Trying to access undefined member 'length'".
Error relates to "thePath" where I write the name of folder on the server.
When I replace real data to model "ftp://username:password@theServer/thePath" and I put it in browser, everything is OK.
I do not know what I'm doing wrong?
Aleksander
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Re: How to call 'FTP receive'
You have to add the following properties in Scripter:
- server
- path
- username
- password
Re: How to call 'FTP receive'
I did like this, I just changed my login details 

Code: Select all
// FTPget - get file from FTP server
//
// Developed by Dwight Kelly <dkelly@apago.com>
// Copyright 2015 - Apago, Inc. -- All rights reserved
//
// Switch logging & output levels
const cLogAssert = -2;
const cLogDebug = -1;
const cLogInfo = 1;
const cLogWarning = 2;
const cLogError = 3;
const cLogProgress = 5;
function jobArrived( s : Switch, job : Job )
{
var theServer = s.getPropertyValue("##.###.###.##");
if (theServer.length == 0) {
job.fail("FTPget: No Server specified!");
return;
}
var thePath = s.getPropertyValue("FILES");
if (thePath.length == 0) {
job.fail("FTPget: No path specified!");
return;
}
var username = s.getPropertyValue("######");
var password = s.getPropertyValue("######");
var f = new File(thePath);
var newFileName = job.createPathWithName(f.name, false);
delete f;
var argc = 0;
var args = new Array();
args[argc++] = "ftp";
args[argc++] = "ftp://"+username+":"+password+"@"+theServer+"/"+thePath;
args[argc++] = "-o"; args[argc++] = newFileName;
var exitStatus = Process.execute(args);
if (exitStatus == 0) {
job.sendToData(3, newFileName);
} else {
job.log(cLogError, "FTPget: download failed, " + Process.stdout);
job.sendToData(3, job.getPath());
}
}
Aleksander
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Re: How to call 'FTP receive'
Here's the complete script element
https://www.dropbox.com/s/jykn52cjef8zo ... cript?dl=0
Dwight Kelly <dkelly.at.apago.com>
https://www.dropbox.com/s/jykn52cjef8zo ... cript?dl=0
Dwight Kelly <dkelly.at.apago.com>
Re: How to call 'FTP receive'
Just a note: I believe the Environment class's download() function also supports simple ftp, so you can omit the Process invocation with
Code: Select all
s.download( "ftp://"+username+":"+password+"@"+theServer+"/"+thePath );
Re: How to call 'FTP receive'
Thanks to all, nobody said it will be easy 
I think the problem is Windows.
I found that the only effective way to call the service ftp.exe is through Batch file or VBScript with Batch file.
But I'm not sure this is a good way.
I think I’ll look for a different solution.
First download all files using the 'FTP receive', then from location where the downloaded files are, I choose needed files based on Metadata.
What do you think?

I think the problem is Windows.
I found that the only effective way to call the service ftp.exe is through Batch file or VBScript with Batch file.
But I'm not sure this is a good way.
I think I’ll look for a different solution.
First download all files using the 'FTP receive', then from location where the downloaded files are, I choose needed files based on Metadata.
What do you think?
Aleksander