Uploading/Downloading/Deleting Files Examples

CLI:

# Upload all files/folders under "dpfiles".
# "cleanDirectories" will automatically delete all files from the directory
# on the device where we're uploading the files to.
# "flushCache" will automatically flush the document/stylesheet caches for all XML managers
dpbuddy copy -toDir wsdl -flatten -includes "dpfiles/**/*.wsdl" -cleanDirectories -flushCache
# Download multiple files from the device, do not re-create the DataPower directories locally (because of "flatten"), 
# clean the local folders
dpbuddy download -include="local:/wsdl/.*" -toDir download -flatten -cleanToDir
# Delete all xsds on "local:"
dpbuddy delete -include "local:/.*\.xsd" -matchRequired false -dryRun true
dpbuddy mkdir -dir="/dir1/dir2"
dpbuddy rmdir -dir="/dir1/dir2"

Ant:

<project name="dpbuddy.samples.files" xmlns:dp="antlib:com.myarch.dpbuddy" >

    <description>
        Samples demonstrating the use of DPBuddy's file/directory management tasks.
    </description>

    <target name="copy" description="Upload files to the device">
        <!-- Root directory for our wsdl files on the device (under local:/)-->
        <property name="dp.wsdl.dir" value="wsdl" />
        
        <!-- Replace backend URLs in WSDL with these values-->
        <property name="person.service.backend.url" value="http://server:12345/personService"/>
        <property name="another.service.backend.url" value="http://server:12345/anotherService"/>

        <property name="location.xpath" value="//@*[local-name() = 'location']"/>

        <!-- DPBuddy will upload all files matched by nested filesets using a single SOMA request-->
        <!-- cleanDirectories="true" will automatically delete all files from the directory
        on the device where we're uploading the files to -->
        <!-- flushCache="true" will automatically flush the document/stylesheet caches for 
        all XML managers -->
        <dp:copy cleanDirectories="true" toDir="${dp.wsdl.dir}" flushCache="true">
            <!-- 
                dpfileset has the same attributes and nested elements as Ant fileset. 
                "toDir" defines the root directory on the device.

                The task automatically replicates the entire local directory tree (including
                all subdirectories that have matching files) on the device.
                'local:' filesystem is the default.
            -->
            
            <!-- Copy WSDL files, replace location before uploading. -->
            <dpFileset dir="${dpfiles.home}" includes="**/PersonService.wsdl">
                <transform> 
                    <setText xpath="${location.xpath}" value="${person.service.backend.url}" />
                </transform>
            </dpFileset>
            <dpFileset dir="${dpfiles.home}" includes="**/AnotherService.wsdl">
                <transform> 
                    <setText xpath="${location.xpath}" value="${another.service.backend.url}" />
                </transform>
            </dpFileset>
            <!-- Copy xsds without any transformations into a different directory.
            Note how the default directory can be overridden at a fileset level -->
            <dpFileset toDir="/xsd" dir="${dpfiles.home}" excludes="**/*.wsdl" />

            <!-- Use matchRequired if files/directories may not exist -->
            <dpFileset dir="/invalidDir" includes="**/PersonService.wsdl" 
                errorOnMissingDir="false" matchRequired="false"/>

        </dp:copy>

        <!-- dump all files to the same directory -->
        <dp:copy cleanDirectories="true" toDir="/services/wsdl" flatten="true" 
            dir="${dpfiles.home}" includes="**/*.xsd **/*.wsdl" />

    </target>

    <!-- Download multiple files from the device -->
    <target name="download" description="Download files">
        <!-- Download all files from "wsdl" directory -->
        <dp:download include="local:/wsdl/.*" toDir="download"
            flatten="true" cleanToDir="true" />
        <!-- Download all xsd files from local:/. Do not fail if no xsd file was found. -->
        <dp:download include="local:/.*xsd" toDir="download" matchRequired="false" cleanToDir="false" />
    </target>
                   
    <!-- Delete files and directories based on the pattern -->
    <target name="delete.files" description="Delete files">
        <!-- Delete all files from "wsdl" directory (but keep the directory itself)-->
        <dp:delete include="local:/wsdl/.*" dryRun="true" />
        <!-- Delete all xsd files from local:/. Do not fail if no xsd file was found. -->
        <dp:delete include="local:/.*\.xsd" matchRequired="false" dryRun="true"/>

    </target>

    <target name="clean.local" description="Completely clean local:/ filesystem" >
        <!-- If you have RAID mount point on local, you need to exclude it using 
        the lookahead regexp similar to below -->
        <dp:delete include="local:/(?!ondisk$).*" matchRequired="false" dryRun="true" />
    </target>

    <target name="mkdir" description="Create a directory on the device">
        <!-- You can create multiple directories using nested "dir" element -->
        <dp:mkdir dir="/dir1/dir2" >
            <dir path="/dir3"/>
            <dir path="/dir4"/>
        </dp:mkdir>
    </target>

    <target name="rmdir" description="Delete a remote directory">
        <!-- Set failOnError to false if you don't want to fail if the directory doesn't exist-->
        <dp:rmdir dir="/dir1/dir2" failOnError="true" >
            <dir path="/dir3"/>
            <dir path="/dir4" />
        </dp:rmdir>
    </target>

    <target name="files.all" depends="copy, download, delete.files, clean.local, mkdir, rmdir" />

</project>