Send file over FTP

Posted by Jorrit on 22-Jan-2016 04:28

Hi,

Could anybody help me?

I want to send an XML file to an FTP server using a serverside trigger.

Is there any possibility in rollbase or JS?

thanks in advance,

Regards Jorrit

Posted by Shiva Duriseati on 10-Feb-2016 04:30

Hi Jorrit,

Please use the following code,since we need file object from {!link#url}. Also make sure to add one more package to the customclassloader property in shared.properties file.

After modification,in shared.properties please add one more package to the existing packages as below.

CustomClassFilter=(sun.net.ftp.*)|(java.net.*)|(java.lang.*)|(java.io.*)|(sun.net.www.protocol.*)

In object script please use the following code.

var ftp_serv = "localhost";

var username = "shiva.duriseati";

var password = "password1234";

var ftpClient = new Packages.sun.net.ftp.FtpClient.create(ftp_serv);

ftpClient.login(username, password.split('')); //Using split() method,since login method accepts  (String,char array)

var url=new Packages.java.net.URL("{!link#url}");// Assuming it is "File Upload" data type.

var inputStream=url.openStream();

ftpClient.putFile("lead.xml", inputStream);

inputStream.close(); //Make sure to close inputstream and ftpclient.

ftpClient.close();

Also, please make sure to check the option "Make files publicly accessible (do not require login)" in "Field Upload" data type.

Please revert back if you need any further assistance.

Regards,

Shiva

All Replies

Posted by Shiva Duriseati on 22-Jan-2016 05:11

Hi Jorrit,

Unfortunately ,object script in rollbase or javascript speaks only HTTP and WebSockets (on newer browsers),and not FTP.

If your XML file is a report on objects, then you can still use batch job to push the file(supported formats, CSV,XLS,XML and XLSX) to FTP server.

Please create the batch job of type "FTP Data Snapshot".

See the below link for more details.

documentation.progress.com/.../index.html

Regards,

Shiva

Posted by Jorrit on 22-Jan-2016 05:53

Hi Shiva,

We have a object called order.

in order object have workflow and status.

On finalize of the order (status invoice) i want to send a template (defined in the object order) on a remote FTP for transaction of the invoice.

Can we start the batchjob on finalise of the order specific with information about the order?

Thanks in advance,

regards Jorrit

Posted by Anoop Premachandran on 22-Jan-2016 06:42

If you are in Private Cloud, you can add ftp client java classes to be exposed to Rollbase javascript. Then you can call these Java methods from Object Script to send data to FTP

See CustomClassFilter documentation here - documentation.progress.com/.../index.html

Posted by Jorrit on 22-Jan-2016 07:31

Hi Anoop,

Can you please tell me more on how to setup the custom JAVA Classes with Private cloud?

thanks in advance.

Regards Jorrit

Posted by Shiva Duriseati on 22-Jan-2016 07:55

Hi Jorrit,

You can also achieve this by creating reports.

Under Reports tab, create a new tabular report on order object , use this report in "FTP Data Snapshot" batch job and specify the output format as required(CSV,XLS,XML and XLSX).

I created a sample tabular report on sample object and specified this report in "FTP data snapshot" batch job formatter as XML . When I run the job this report gets pushed into FTP server.

Please find attached screenshots.

Regards,
Shiva

Posted by Jorrit on 22-Jan-2016 08:01

Hi Shiva,

Ok but can i run this batch when the order gets the status invoiced?

And is it possible to rename the snapshot? like give it the ordernumber?

Regards Jorrit

Posted by Shiva Duriseati on 22-Jan-2016 08:23

Hi Jorrit,

Yes, you can run the batch job as and when you required. Please specify the condition while creating batch job,in the script section available under "Trigger Condition Formula" section which returns boolean.

Yes,its possible to rename the file name.

Regards,

Shiva

Posted by Jorrit on 01-Feb-2016 06:31

Hi Shiva,

can you give me an example how to start the batchjob from objectscript and rename the report from objectscript?

Regards,

Jorrit

Posted by Jorrit on 06-Feb-2016 05:12

Hi Anoop,

can you please help me loading custom JAVA class in Private Cloud?

Regards,

Jorrit

Posted by Shiva Duriseati on 06-Feb-2016 08:13

Hi Jorrit,

Please add "CustomClassFilter" in shared.properties in the following way.

ex: CustomClassFilter=(sun.net.ftp.*)|(java.net.*)|(java.lang.*)|(java.io.*) // You can add multiple packages seperated by "|".

In object script ,you can use FTP client object the following way:

For example : var ftpCilent=new Packages.sun.net.ftp.FtpClient.create("localhost");

                       ftpCilent.login(username, password.split(''));

For the previous query, you cannot start batch job from object script, but you can start trigger from batch job.

Regards,

Shiva

Posted by Jorrit on 08-Feb-2016 02:02

Hi Shiva,

Thanks, do i need to copy some packages on the server when setting CustomClassFilter or is the sun.net.ftp* default available?

And where can i found examples about setting up the connection and push files to ftp?

regards Jorrit

Posted by Shiva Duriseati on 08-Feb-2016 06:22

Hi Jorrit,

Manual copying of sun.net.ftp.* is not required, since it is a default package available in runtime jar/"rt.jar" which will always reside under $JAVA_HOME/jre/lib(where $JAVA_HOME refers to JDK installation directory).

Please use the following code in "object script" trigger.

              var ftp_serv = "localhost";

      var username = "shiva.duriseati";

      var password = "password1234";

      var ftpClient = new Packages.sun.net.ftp.FtpClient.create(ftp_serv);

      ftpClient.login(username, password.split('')); //Using split() method,since login method accepts  (String,char array)

      var file=new Packages.java.io.File("D://Sample_v2.xml");//This file needs to get from token helper

              var inputStream=new Packages.java.io.FileInputStream(file);

      ftpClient.putFile("renamefile.xml", inputStream);

      inputStream.close(); //Make sure to close inputstream and ftpclient.

      ftpClient.close();

The above code pushes "Sample_v2.xml" to FTP server with the name "renamefile.xml" . I hope this clarifies.

Regards,

Shiva

Posted by Jorrit on 08-Feb-2016 08:35

Hi Shiva,

Thank you very much.. i am almost there!!

var file=new Packages.java.io.File("D://Sample_v2.xml");//This file needs to get from token helper

How can i set the variable file from the template helper? the only thing i have is the {!link#url} from the document template.

so i dont have a file with filelocation.

sorry i am realy new to java ;)

thanks in advance.

regards Jorrit

Posted by Shiva Duriseati on 10-Feb-2016 04:30

Hi Jorrit,

Please use the following code,since we need file object from {!link#url}. Also make sure to add one more package to the customclassloader property in shared.properties file.

After modification,in shared.properties please add one more package to the existing packages as below.

CustomClassFilter=(sun.net.ftp.*)|(java.net.*)|(java.lang.*)|(java.io.*)|(sun.net.www.protocol.*)

In object script please use the following code.

var ftp_serv = "localhost";

var username = "shiva.duriseati";

var password = "password1234";

var ftpClient = new Packages.sun.net.ftp.FtpClient.create(ftp_serv);

ftpClient.login(username, password.split('')); //Using split() method,since login method accepts  (String,char array)

var url=new Packages.java.net.URL("{!link#url}");// Assuming it is "File Upload" data type.

var inputStream=url.openStream();

ftpClient.putFile("lead.xml", inputStream);

inputStream.close(); //Make sure to close inputstream and ftpclient.

ftpClient.close();

Also, please make sure to check the option "Make files publicly accessible (do not require login)" in "Field Upload" data type.

Please revert back if you need any further assistance.

Regards,

Shiva

Posted by Jorrit on 10-Feb-2016 06:01

Hi Shiva,

You are the Best!! its working!

Thank you very much for the quick and great help!

Regards,

Jorrit

This thread is closed