On windows, the following approach would work:
- Create an ftp script (say, d:\ftpscript.txt) on the webMethods machine:
- Create a batch file (say, d:\ftpls.bat) to execute the script on the webMethods machine:
FTP -v -s:ftpscript.txt [servername] >> d:\ftpoutput.txt
- Create a Java service in webMethods to execute the script:
Process proc = Runtime.getRuntime().exec("cmd /c d:\\ftpls.bat");
int exitVal = proc.waitFor();
throw new ServiceException(t);
Now if you call the service, the batch file will be executed on the webmethods machine. The batch file will log on to the remote ftp server (with the username and password from ftpscript.txt), change to the right directory and list the contents. The output of the ftp commands will be written to ftpoutput.txt.
When this service completes, you can read and parse the file ftpoutput.txt which contains the result of the ftp commands.
The same approach can be used on other platforms, but you will of course need to modify it accordingly.