【问题标题】:DataPower file transfer returns base64DataPower 文件传输返回 base64
【发布时间】:2014-10-02 14:23:56
【问题描述】:

我正在使用以下 cURL 命令将 DataPower 文件从设备获取到远程 Solaris 服务器。

/usr/local/bin/curl -s --insecure --data-binary @getFile.xml -u username:password https://ip:port/service/mgmt/current

getFile.xml 内容如下。

<?xml version="1.0"?>
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
      <env:Body>
           <dp:request xmlns:dp="http://www.datapower.com/schemas/management">
              <dp:get-file name="config:///unicenter.cfg"/>
           </dp:request>
      </env:Body>
    </env:Envelope>

当我在 Solaris 上运行上面提到的 cURL 时,我得到了很长的 base64 编码字符串。但我希望将完整的文件复制到 Solaris。

【问题讨论】:

    标签: xslt curl base64 ibm-datapower


    【解决方案1】:

    Base64 编码的长字符串您的文件。您需要做一些工作来提取它。

    这个 curl 命令使用 DataPower XML 管理接口,他们之所以这么称呼它是因为所有请求和响应都是 XML 格式的。当长字符串飞过时,您可能没有看到它,但它是用 XML 包装的。这是一个带有小负载的示例响应:

      <?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>
    

    所以,你有两个工作要做。首先,从 XML 包装器中取出 Base64 字符串,然后对其进行解码。有一百万种方法可以做到这一点——我会给你其中一种。获取XmlStarlet 的副本以进行提取,并获取OpenSSL 的副本以进行Base64 解码。

    然后,像这样通过管道输出 curl:

    /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
    

    两个快速说明——“&& echo”是添加尾随换行符,“fold”是将 Base64 字符串拆分为行。不太挑剔的 Base64 解码器不需要这些。我刚刚选择了“openssl”,因为大多数人已经拥有它。

    【讨论】:

      猜你喜欢
      • 2014-08-22
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      相关资源
      最近更新 更多