【问题标题】:Check, if a file has changed, before downloading it from SFTP server using Apache Ant在使用 Apache Ant 从 SFTP 服务器下载文件之前检查文件是否已更改
【发布时间】:2016-12-16 08:33:07
【问题描述】:

我正在使用 Ant <scp> 任务从 SFTP 服务器下载文件。我想检查该文件是否在本地存在,如果存在,是否与服务器上的文件相同。 (如何)可以在下载之前比较时间戳或哈希?

<scp file="${ftp.user}:${ftp.password}@${ftp.url}:/my/path/*"
      failonerror="false"
      verbose="yes"
      sftp="true"
      trust="true"
      todir="${target.dir}"/>

【问题讨论】:

    标签: ant sftp


    【解决方案1】:

    我用校验和文件解决了我的问题:

    <checksum file="${temp.dir}${file.separator}my.zip" algorithm="SHA-512" property="zip-checksum"/>
    <scp file="${ftp.user}:${ftp.password}@${ftp.url}:/my/path/my.zip.asc"
      failonerror="false"
      verbose="no"
      sftp="true"
      trust="true"
      todir="${temp.dir}"/>
    <loadfile srcfile="${temp.dir}/my.zip.asc" property="my-other-zip">
      <filterchain>
        <striplinebreaks/>
        <trim/>
      </filterchain>
    </loadfile>
    <checksum file="${temp.dir}${file.separator}my.zip" property="${my-other-zip}" verifyProperty="zip-checksum-match"/>
    <if>
      <equals arg1="${zip-checksum}" arg2="${my-other-zip}"/>
      <then>
        <echo level="info">Checksum of my.zip (local) is equal to my.zip (server). Skipping...</echo>
      </then>
      <else>
        <echo level="info">Checksum of my.zip (local) is not equal to my.zip (server). Get new zip...</echo>
        <scp file="${ftp.user}:${ftp.password}@${ftp.url}:/my/path/my.zip"
          failonerror="false"
          verbose="no"
          sftp="true"
          trust="true"
          todir="${temp.dir}"/>
      </else>
    </if>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 2012-06-13
      • 2013-12-21
      • 2018-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多