Listening for events

Top  Previous  Next

For an object to listen for events published by the Fxp class the following steps are required:

 

1.Set object to implement FxpListener class.
2.Overload event handling methods.
3.Subscribe object to receive events published by Fxp instance.

 

Example

 

import com.jscape.inet.ftp.*;

 

public class FxpExample implements FxpListener {

 

 /**

  * Create new FxpExample instance

  */        

 public FxpExample() {

         // create new Fxp instance

         Fxp fxp = new Fxp();

         

         // subscribe to listener

         fxp.addFxpListener(this);

         

         // write additional code here to do transfer                

 }

 

 /**

  * Invoked when FXP transfer starts for a file.

  *

  * @param ev a <code>FxpStartEvent</code>

  * @see FxpStartEvent

  */        

 public void fxpStart(FxpStartEvent ev) {

         Ftp source =(Ftp)ev.getSource();

         Ftp dest = (Ftp)ev.getDestination();

         System.out.println("Starting transfer of " + ev.getFilename() + " from " +

                 source.getHostname() + " to " + dest.getHostname());

 }

 

 

 /**

  * Invoked when FXP transfer ends for a file.

  *

  * @param ev a <code>FxpEndEvent</code>

  * @see FxpEndEvent

  */        

 public void fxpEnd(FxpEndEvent ev) {

         Ftp source =(Ftp)ev.getSource();

         Ftp dest = (Ftp)ev.getDestination();

         System.out.println("Ending transfer of " + ev.getFilename() + " from " +

                 source.getHostname() + " to " + dest.getHostname());                

 }

 

 

 /**

  * Invoked when FXP transfer fails for a file.

  *

  * @param ev a <code>FxpFailedEvent</code>

  * @see FxpFailedEvent

  */                

 public void fxpFailed(FxpFailedEvent ev) {

         Ftp source =(Ftp)ev.getSource();

         Ftp dest = (Ftp)ev.getDestination();

         System.out.println("Failed transfer of " + ev.getFilename() + " from " +

                 source.getHostname() + " to " + dest.getHostname());                

 }

}

 

See also

 

Event types





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

© 2021 JSCAPE LLC