开发者

Delete all files and folders via Ant FTP task

开发者 https://www.devze.com 2023-04-13 05:53 出处:网络
How to delete all files and folders inside specified remote folder in Ant? I\'ve tried the following: <ftp server=\"${ftp.host}\" userid=\"${ftp.user}\"

How to delete all files and folders inside specified remote folder in Ant?

I've tried the following:

<ftp server="${ftp.host}" userid="${ftp.user}"
             password="${ftp.pass}" remotedir="${ftp.remotedir}" action="del">
    <fileset>
        <include name="**/*"/>
    </fileset>
</ftp>

it deletes al开发者_高级运维l files, but not folders. (if I write here <include name="*.txt"> instead it works as expected - deletes all txt files, but what if I want to delete all files and folders?)


You should use another command: rmdir.
This command does not remove folder specified in the remotedir parameter.
The sample based on information from ant.apache.org:

  <ftp action="rmdir"
       server="${ftp.host}"
       userid="${ftp.user}"
       password="${ftp.pass}"
       remotedir="${ftp.parentdir_for_remotedir}" >
    <fileset>
      <include name="${ftp.remotedir}/**"/>
    </fileset>
  </ftp>

The quote from site:

The directory specified in the remotedir parameter is never selected for remove, so if you need to remove it, specify its parent in remotedir parameter and include it in the pattern, like "somedir/**".

Also worth noting is that rmdir will fail if there are anything but empty folders in the fileset specified.

From the same site:

As an example suppose you want to delete everything contained into /somedir, so invoke first the task with action="delete", then with action="rmdir" ...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号