Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
ftpclientscriptexample [2022/01/15 23:01] wikiadmin created |
ftpclientscriptexample [2024/12/28 08:36] (current) wikiadmin |
||
---|---|---|---|
Line 2: | Line 2: | ||
This script uses the FTPClient from Apache Commons Net. It includes testing for all errors after each step, except timeouts. fileName and its localPath are passed in as parameters. The return is a String which has the error description in it, or is " | This script uses the FTPClient from Apache Commons Net. It includes testing for all errors after each step, except timeouts. fileName and its localPath are passed in as parameters. The return is a String which has the error description in it, or is " | ||
+ | |||
+ | The example below is set up as a function. Place the function code at the top of your script, with the main script and code that calls this function below it. For example: | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | function ftpFile (fileName, | ||
+ | .... | ||
+ | } | ||
+ | |||
+ | //Main script | ||
+ | |||
+ | //call the ftp with a filename and path | ||
+ | |||
+ | result = ftpFile(" | ||
+ | if (result.equals(" | ||
+ | //file was successfully transferred. | ||
+ | } else { | ||
+ | //there was an error | ||
+ | print(result); | ||
+ | } | ||
+ | </ | ||
====Setup==== | ====Setup==== | ||
Line 19: | Line 40: | ||
If the ftpHostname is blank, ftp will be disabled. | If the ftpHostname is blank, ftp will be disabled. | ||
+ | |||
+ | ====Script for FTP==== | ||
<code javascript> | <code javascript> | ||
+ | |||
//FTP the a file to the server configured in ErgoTechConfiguration.properties | //FTP the a file to the server configured in ErgoTechConfiguration.properties | ||
function ftpFile (fileName, | function ftpFile (fileName, | ||
+ | |||
+ | var System = Java.type(" | ||
hostname = System.getProperty(" | hostname = System.getProperty(" | ||
Line 72: | Line 98: | ||
| | ||
| | ||
+ | // to transfer binary files, use the following call (not required for ASCII transfers). | ||
+ | | ||
| | ||
Line 93: | Line 121: | ||
} | } | ||
- | } //end of ftpResults | + | } //end of ftpFile |
</ | </ | ||
+ | |||
+ | ====Running the FTP Client script==== | ||
+ | |||
+ | The Apache Commons Net 3.x jar (i.e. commons-net-3.1.jar) will need to be on the classpath to run this script. This is included in MIStudio and the TransSECS Devices installation, | ||
+ |