Page 1 of 1
How to call 'FTP receive'
Posted: Wed Mar 25, 2015 10:38 am
by _olq
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
Re: How to call 'FTP receive'
Posted: Wed Mar 25, 2015 5:40 pm
by dkelly
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'
Posted: Thu Mar 26, 2015 9:33 am
by _olq
Thanks Dwight,
What do you mean by script. From what I know Java Script does not support FTP protocol.
Can you give a hint?
Re: How to call 'FTP receive'
Posted: Thu Mar 26, 2015 2:32 pm
by dkelly
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'
Posted: Thu Mar 26, 2015 3:54 pm
by _olq
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?
Re: How to call 'FTP receive'
Posted: Thu Mar 26, 2015 5:09 pm
by dkelly
You have to add the following properties in Scripter:
- server
- path
- username
- password
Re: How to call 'FTP receive'
Posted: Thu Mar 26, 2015 5:51 pm
by _olq
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());
}
}
Re: How to call 'FTP receive'
Posted: Thu Mar 26, 2015 9:33 pm
by dkelly
Here's the complete script element
https://www.dropbox.com/s/jykn52cjef8zo ... cript?dl=0
Dwight Kelly <dkelly.at.apago.com>
Re: How to call 'FTP receive'
Posted: Fri Mar 27, 2015 9:32 am
by bens
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'
Posted: Fri Mar 27, 2015 10:15 am
by _olq
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?