Clarity

 View Only
  • 1.  Delete File in CA Cloud SFTP

    Posted Aug 29, 2018 03:55 PM

    Hi All

     

    Is there a way to delete a file in CA Cloud SFTP? Is that doable with the GEL script? Could you please advise on this? 



  • 2.  Re: Delete File in CA Cloud SFTP

    Posted Aug 29, 2018 08:05 PM

    We are able to access the CA SFTP either via logging in through an SFTP application like Filezilla or we access the SFTP from within the CA PPM application front end.

     

    We use a portlet that is was deployed called 'Data Extract View Initiation' - which I believe is part of the PMO accelerator content. Someone from either CA Services or Support will be able to confirm this. This is a HTML portlet and from within this portlet we can delete files directly within the CA SFTP. When we run data extracts they are located into the CA SFTP as well and the manual method we use to access / retrieve these files is via this portlet as well.

     

    I first came across this portlet on v14.2, and in subsequent releases it has always been present.



  • 3.  Re: Delete File in CA Cloud SFTP

    Posted Sep 04, 2018 03:49 PM

    Thank you for the information. The limitation is that we don't have access to CA SFTP via any SFTP connectivity application because of the security issues. What is the Data Extraction View Initiation portlet that you're referring to? Where can i access that portlet? Would that be possible to delete files via that portlet? 



  • 4.  Re: Delete File in CA Cloud SFTP

    Posted Aug 29, 2018 08:21 PM

    Yes, it should be possible to delete a file in SFTP folder using GEL. You have to invoke java.io.File.delete() method.

    ChrisYardin  - 'Data Extract View Initiation' is a HMTL portlet which is part of Data Extraction. That portlet internally invokes set of jsp files for the operations performed by the portlet(deleting file is one among them).



  • 5.  Re: Delete File in CA Cloud SFTP

    Posted Sep 04, 2018 04:43 PM

    Hi pdesur thank you for the reply, is there a pseudo code that can help me understand the java.io.File.delete()  better? Or any documentation on the java method would work? 



  • 6.  Re: Delete File in CA Cloud SFTP
    Best Answer

    Posted Sep 04, 2018 09:34 PM

    Here is the snippet of  java code:

     

    File file = new File("C:\\file.txt"); -- Provide file path

    boolean result;
    try {
     // delete the file specified
     result = file.delete();
     if (result) {
      System.out.println("Successfully deleted: ");
     } else {
      System.out.println("Failed deletion");
     }
    } catch (IOException e) {
    }

     

    Utilize same method in GEL to delete the files.



  • 7.  Re: Delete File in CA Cloud SFTP

    Posted Sep 05, 2018 10:59 AM

    thank you pdesur!



  • 8.  Re: Delete File in CA Cloud SFTP

    Posted Sep 06, 2018 11:04 AM

    Here is a gel example of using java.io.File which finds the latest file in a directory.

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
         xmlns:core="jelly:core"
         xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


         <gel:log>Start GetLatestFile Script</gel:log>
         
         <core:set var="logPath" value="D:\\clarity\\logs"/>
         <gel:log>LogPath = ${logPath}</gel:log>
         
         <core:new className="java.io.File" var="logDir" >
              <core:arg type="java.lang.String" value="${logPath}" />
         </core:new>
         <core:if test="${logDir.isDirectory()}" >
              <core:invoke method="listFiles" on="${logDir}" var="logFiles" />
              <gel:log>Found ${size(logFiles)} log files in ${logPath}</gel:log>

              <core:if test="${size(logFiles)&gt; 0}">
                   <core:set var="lastModifiedFile" value="${logFiles[0]}"/>
                   <core:forEach items="${logFiles}" var="file">
                             <core:if test="${lastModifiedFile.lastModified() &lt; file.lastModified()}">
                                  <core:set var="lastModifiedFile" value="${file}"/>
                             </core:if>
                   </core:forEach>
                        <gel:log>The latest file is ${lastModifiedFile.getAbsolutePath()}</gel:log>
              </core:if>
         </core:if>
         
         <gel:log>End GetLatestFile Script</gel:log>

    </gel:script>

     

    The api documentation File (Java Platform SE 7 ) 

     

    V/r,

    Gene



  • 9.  Re: Delete File in CA Cloud SFTP

    Posted Dec 10, 2018 09:39 AM

    Hi all,

    as I have a SFTP question and you guys seem to know very well about it I am posting my small issue (Could not parse responde code for ftp:open tag) here:

     

    org.apache.commons.jelly.JellyTagException: null:20:97: <ftp:open> Could not parse response code.

    Server Reply: SSH-2.0-OpenSSH_7.4

                             at com.niku.union.gel.tags.ftp.OpenTag.openFTP(OpenTag.java:78)

    Caused by: org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
    Server Reply: SSH-2.0-OpenSSH_7.4
                             at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:331)

    Here is my GEL script trying to write on our SFTP folder:

    <gel:parameter var="clarityURL" default="https://cppmXXXX-test.ondemand.ca.com"/>

    <gel:parameter var="clarityUser" default="admin"/>

    <gel:parameter var="claritypwd" default="***!" secure="true"/>

     

    <gel:parameter default="/Clarity" var="sharefolder"/>

    <gel:parameter default="/Clarity" var="docPath"/> 

     

    <gel:parameter default="10000" var="end"/>

    <gel:setDataSource dbId="niku"/>

    <gel:parameter default="C:\temp" var="inputfolder"/>

     

    <core:set value="${inputfolder}\test_ray.txt" var="file_read"/>

    <ftp:open hostName="sftp3.ondemand.ca.com" port="22" user="MUNXXXX" password="xyz">

                   <ftp:put fileName="${file_name}" localDir="${file_read}" remoteDir="/home/MUNXXXX/sftp/Development/SCP"/>

    </ftp:open>

     

    many thanks in advance for any kind of help!

    Olivier



  • 10.  Re: Delete File in CA Cloud SFTP

    Broadcom Employee
    Posted Dec 10, 2018 10:43 AM
    Olivier
    You shouldn't really cross-post like this but see my reply below.
    Not sure you need the 'http://' in the hostName, for 2 reasons:
    1 - You are making an FTP call so it is unlikely that an HTTP endpoint will respond
    2 - The rest of the host name suggests secure FTP so you are more likely to need HTTPS (but see above for why an HTTP endpoint is unlikely to respond)
    Try removing the 'http://' from the hostName attribute