Send file over FTP - Forum - Rollbase - Progress Community

Send file over FTP

 Forum

Send file over FTP

This question is answered

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

Verified Answer
  • 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
  • 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

  • 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

  • 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

  • Hi Anoop,

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

    thanks in advance.

    Regards Jorrit

  • 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

  • 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

  • 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

  • Hi Shiva,

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

    Regards,

    Jorrit

  • Hi Anoop,

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

    Regards,

    Jorrit

  • 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

  • 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

  • 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

  • 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

  • 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

  • Hi Shiva,

    You are the Best!! its working!

    Thank you very much for the quick and great help!

    Regards,

    Jorrit