Running FTCL scripts from within Java

Top  Previous  Next

FTCL scripts may be processed from within Java code by creating a new FTCL instance and invoking the appropriate execute() method. Scripts may be executed from a file or from an array of bytes. The necessary FTCL classes are located in the Secure FTP Factory sftp.jar file.

 

Example

 

import com.jscape.ftcl.FTCL;

import com.jscape.ftcl.FTCLException;

 

import java.io.File;

 

public class FTCLExample {

public static void main(String[] args) {

  // create new FTCL instance

   FTCL ftcl = new FTCL();

 

  // load script file

   File script = new File("c:/ftpscript.txt");

 

  // execute script and capture any exceptions

  try {

     ftcl.execute(script);

   } catch(FTCLException fe) {

     fe.printStackTrace();

   }  

 }

}

 

 

Example

 

import com.jscape.ftcl.FTCL;

import com.jscape.ftcl.FTCLException;

 

public class FTCLExample {

public static void main(String[] args) {

  // create new FTCL instance

   FTCL ftcl = new FTCL();

 

  // create buffer that contains commands to execute

   StringBuffer buffer = new StringBuffer();

   buffer.append("set hostname \"ftp.myserver.com\"\r\n");

   buffer.append("set username \"jsmith\"\r\n");

   buffer.append("set password \"secret\"\r\n");

   buffer.append("connect\r\n");

   buffer.append("dir\r\n");

   buffer.append("disconnect\r\n");  

 

  // execute script and capture any exceptions

  try {

    byte[] data = buffer.toString().getBytes();

     ftcl.execute(data);

   } catch(FTCLException fe) {

     fe.printStackTrace();

   }  

 }

}





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC