DataPower file transfer returns base64 DataPower file transfer returns base64 curl curl

DataPower file transfer returns base64


The long Base64-encoded string is your file. You need to do a little work to extract it.

This curl command is using the DataPower XML Management interface, and they call it that because all requests and responses are XML-formatted. You may not have seen it as the long string flew by, but it was wrapped in XML. Here's a sample response with a small payload:

  <?xml version="1.0" encoding="UTF-8"?>  <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">    <env:Body>      <dp:response xmlns:dp="http://www.datapower.com/schemas/management">        <dp:timestamp>2014-10-23T17:12:39-04:00</dp:timestamp>        <dp:file name="local:///testfile.txt">VGhpcyBpcyBub3QgYW4gYWN0dWFsIGVtZXJnZW5jeS4K</dp:file>      </dp:response>    </env:Body>  </env:Envelope>

So, you have two jobs to do. First, get the Base64 string out of its XML wrapper, and second, decode it. There are a million ways to do this -- I'll give you one of them. Get a copy of XmlStarlet to do the extraction, and OpenSSL to do the Base64 decoding.

Then, pipe the curl output like so:

/usr/local/bin/curl -s --insecure --data-binary @getFile.xml -u username:password https://ip:port/service/mgmt/current \| (xmlstarlet sel -T -t -v "//*[local-name()='file']" && echo) \| fold -w 64 \| openssl enc -d -base64 >this-is-the-real-file

Two quick notes -- the "&& echo" is to add a trailing newline, and the "fold" is to split the Base64 string into lines. A less finicky Base64 decoder wouldn't need these. I just picked "openssl" because most people already have it.