Overview
This article will demonstrate how to write your own custom actions using JSCAPE Secure FTP Server Action API. These 'actions' respond to certain events such as uploading a file or forwarding it as an attachment to the recipient.
Requirements
1) JDK 1.4.2 or above. 2) JSCAPE Secure FTP Server.
Java Class Overview
A new java class will be written extending AbstractAction which can be found in JSCAPE Secure FTP Server Action API. To use this API in your Java program data.jar must be added to your project classpath in your IDE. This jar file can be found in JSCAPE Secure FTP Server installation directory.
JSCAPE Secure FTP Server uses reflection on action classes to build the GUI screens used in collecting action variable data. This is very useful in that when defining actions you do not have to define separate GUI screens for collecting the data as they are automatically generated using reflection and information found in the action class itself. However, in order for JSCAPE Secure FTP Server to generate these GUI panels automatically there are some rules that you must follow.
- Classes must have an empty constructor. This allows JSCAPE Secure FTP Server to create an instance without having to know what class constructor it should use.
- Exposed class variables must be primitives e.g. String, int, long, boolean etc.
- Exposed class variables must have corresponding getter and setter methods using Java naming conventions. For example, the String variable 'file' would have getter and setter methods of 'getFile' and 'setFile' respectively.
Java Code [Download CodeExample.java] :
1 package test.com.jscape.action;We are going to define an action for a file upload trigger. Whenever a file is uploaded
2 import com.jscape.inet.mft.workflow.AbstractAction;
3 import com.jscape.inet.smtp.Smtp;
4 import com.jscape.util.reflection.PropertyDescriptor;
5 import com.jscape.util.reflection.StringField;
6 import com.jscape.util.reflection.types.*;
7 import com.jscape.inet.email.*;
8 import com.jscape.inet.mime.*;
9
10 public class Main extends AbstractAction
11 {
12 private static final String DESCRIPTION = "Forward file to email address";
13 private static final PropertyDescriptor[] DESCRIPTORS =
14 {
15 new PropertyDescriptor("File", true, new FileField()),
16 new PropertyDescriptor("Email", true, new StringField()),
17 };
18
19 private String file;
20 private String email;
21
22 public String getFile()
23 {
24 return file;
25 }
26
27 public void setFile(String file)
28 {
29 this.file = file;
30 }
31
32 public String getEmail()
33 {
34 return email;
35 }
36
37 public void setEmail(String email)
38 {
39 this.email = email;
40 }
41
42 public String getDescription()
43 {
44 return DESCRIPTION;
45 }
46
47 public PropertyDescriptor[] getPropertyDescriptors()
48 {
49 return DESCRIPTORS;
50 }
51
52 protected void execute() throws Exception
53 {
54 Smtp smtp = new Smtp("smtp.server.com");
55 smtp.connect();
56 EmailMessage message = new EmailMessage();
57 message.setTo("to@to.com");
58 message.setFrom("from@from.com");
59 MimeHeader header = new MimeHeader("Content-Disposition","attachment");
60 MimeHeaderAttr filename = new MimeHeaderAttr("filename", file);
61 header.addAttribute(filename);
62 message.addHeader(header);
63 message.setSubject("Test Message");
64 message.setBody("Test");
65 smtp.send(message);
66 smtp.disconnect();
67 }
68 }
to the server it will be forwarded to a specific email address. In a real scenario you would
probably have restrictions including the type of the file or the size of the uploaded file.
Lines 1-8 : Necessary import statements
Lines 10 : The class must extend AbstractAction to be recognized by JSCAPE Secure FTP
Server.
Line 12 : Description of the action that will appear in the Server Manager GUI.
Lines 13-17 : Two fields defined. They will appear in the Jscape Panel GUI when the
action is defined.
Lines 19-40 : The class level variables and their appropriate getter / setter methods.
Lines 52-67 : The execute method where the file will be forwarded to the appropriate
email address.
Before this action can be used in Jscape Secure FTP Server we need to install it. Go
to the directory where the java class file is located and create a jar file as shown below.
Copy the generated jar file to lib\actions directory of the JSCAPE Secure FTP Server
installation directory. Restart JSCAPE Secure FTP Server Service and the Server Manager.

The action should now appear under domain -> Triggers -> Actions tab with the name
of the class and a description matching the value of the static DESCRIPTION variable.
Jscape Secure FTP Server will generate the GUI shown here based on the variables defined
in the class :

Comments