我正在使用Ant <scp>
任务从SFTP服务器下载文件。我想检查文件是否存在于本地,如果是,则它是否与服务器上的文件相同。 (如何)在下载之前比较时间戳或哈希值?
<scp file="${ftp.user}:${ftp.password}@${ftp.url}:/my/path/*"
failonerror="false"
verbose="yes"
sftp="true"
trust="true"
todir="${target.dir}"/>
答案 0 :(得分:0)
我用校验和文件解决了我的问题:
<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>