I am trying to deploy a Maven site to an FTP server. I am using the following code in my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>post-site</phase>
<configuration>
<tasks>
<ftp action="del" server="nexus"
remotedir="/pub/${project.groupId}/${project.artifactId}"
userid="anonymous" password="my.name@gmail.com"
skipFailedTransfers="true" ignoreNoncriticalErrors="true">
<fileset>
<include name="**/" />
</fileset>
</ftp>
<ftp action="rmdir" server="nexus"
remotedir="/pub/${project.groupId}/${project.artifactId}"
userid="anonymous" password="my.name@gmail.com"
skipFailedTransfers="true" ignoreNoncriticalErrors="true">
<fileset>
<include name="**/" />
</fileset>
</ftp>
<ftp action="mkdir" server="nexus"
remotedir="/pub/${project.groupId}/${project.artifactId}"
userid="anonymous" password="my.name@gmail.com" depends="yes"
verbose="no" chmod="777">
</ftp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Here I delete the previous site deployed, and creating a new directory for the site in the post-site phase, so that the deploy will have the structure it needs. The problem is that it doesn't work for the first time - when folder to delete does not exist. In the first time I must manually create the directory so it will work. after the first time it works well.
my question is how do I check the existence of the directory before trying to delete it.
Thanks, Ronen.
You could do ftp mkdir first before the ftp del task is called, this would ensure the directory exists before deleting it. though of course that might fail if the directory already exists. I'm not able to test this, but according to the docs, adding ignoreNoncriticalErrors="true" might let mkdir not fail if the directory exists.
For example:
Update: From Ftp.java it looks like this will work: