DataPower

 View Only
  • 1.  How (Service) to delete SFTP files from multiple folders using DataPower service

    Posted Thu May 16, 2024 08:08 AM

    Hi everyone

    I am trying to avoid working with crontabs in the Server, I had like to develop a DataPower service that will delete files in a server, I had like to schedule it for a specific date, time and it should delete files older than 3 days, e.g every Wednesday, 12:00 am, files older than 3 days and it should delete files from  certain folders maybe from 80 folders, 

    How possible it is to implement a service like this in the DataPower, please note that I had like to use a GatewayScript but any clue will be great.


    Thank you



    ------------------------------
    Akani Chabalala
    ------------------------------


  • 2.  RE: How (Service) to delete SFTP files from multiple folders using DataPower service

    Posted Thu May 16, 2024 01:27 PM
    Edited by DOMINIC MICALE Thu May 16, 2024 01:27 PM

    Hi Akani,

    DataPower's url-open supports a Delete parameter for files:

    https://www.ibm.com/docs/en/datapower-gateway/10.5.0?topic=open-url-sftp

    I would expect GatewayScript to support that same parameter.

    As far as pulling the directory and parsing I think you will need to look at:

    For directory listings, see the XML Directory Listing schema in store://schemas/filelist.xsd

    Usually there is a client involved (customers SFTP proxy typically), but if you are trying to do something say like a scheduled rule that just calls this backend sftp server you will have to pull the dir listing and then call each delete on a file.



    ------------------------------
    DOMINIC MICALE
    ------------------------------



  • 3.  RE: How (Service) to delete SFTP files from multiple folders using DataPower service

    Posted Tue May 21, 2024 10:53 AM

    Hi Dominic

    your response made me understand that I can just develop a script e.g deleteFiles.sh, then I just send a command to execute it.

     So, in the DataPower I just want to execute the script that will do the rest of deleting the files named "deleteFiles", I currently execute this file manually by running a command line .deleteFiles.sh/

    so right now I want to automate this using a service in the DataPower.

    For starters I tried attempting to send just an ls-l command to the server but when I trigger the mpgw by sending just an empty request I receive a 200ok with no response and it looks like the command is not going through.

    I am having a mpgw, with a rule that contains a router action, which contains a stylesheet, after that a skip back-end then the results:

    stylesheet:

    <!-- Define the SFTP file URL -->
    <xsl:variable name="sftp-file-url" select="'sftp://ip:22'"/>
     
    <!-- Define the SSH command to delete the file -->
    <xsl:variable name="delete-command" select="'ls -l'"/>
     
    <!-- Use URL-Open to execute the delete command on the SFTP server -->
    <xsl:message>Before SFTP command</xsl:message>
    <dp:url-open target="{$sftp-file-url}" response="ignore">
    <dp:headers>
    <dp:header name="X-DP-SSH-CMD" value="{$delete-command}"/>
    </dp:headers>
    </dp:url-open>


    This is not working though I can login to the server using ssh in the DataPower; I am wondering what could be wrong or maybe DP does not actually send the commands to the server or what. 

    thank you



    ------------------------------
    Akani Chabalala
    ------------------------------



  • 4.  RE: How (Service) to delete SFTP files from multiple folders using DataPower service

    Posted Tue May 21, 2024 01:22 PM

    Hi Akani,

    DataPower does not support sending SSH commands you need to specify SFTP urls to do what you need.

    You need to retrieve the directory to get the file listing per my first update:

    To specify a path that represents a directorysftp://[user:password@]host[:port]/~/path/;type=d

    For directory listings, see the XML Directory Listing schema in store://schemas/filelist.xsd

    Then to delete it specify the file in the directory and the Delete=true parameter.

    sftp://[user:password@]host[:port]/~/path/myfile.txt?Delete=true



    ------------------------------
    DOMINIC MICALE
    ------------------------------