Search code examples
mavenftpmaven-antrun-plugin

Unable to dowload file from ftp with maven-antrun-plugin (0 files retrieved)


I'm using maven-antrun-plugin in order to download a dump from a FTP.

Here is my pom.xml :

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>ftp</id>
                    <phase>package</phase>
                    <configuration>
                        <target>
                            <ftp action="get" 
                                 server="myserver" 
                                 remotedir="/remotedir/"
                                 userid="anonymous" 
                                 password="anonymous" 
                                 depends="yes" 
                                 verbose="yes">
                                <fileset dir="${project.build.directory}">
                                    <include name="**/*.*" />
                                </fileset>
                            </ftp>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>commons-net</groupId>
                    <artifactId>commons-net</artifactId>
                    <version>1.4.1</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-commons-net</artifactId>
                    <version>1.8.1</version>
                </dependency>
            </dependencies>
        </plugin>

The plugin seems to work but it doesn't download my dump ("0 files retrieved").

> main:
>       [ftp] Opening FTP connection to myserver
>       [ftp] connected
>       [ftp] logging in to FTP server
>       [ftp] login succeeded
>       [ftp] changing the remote directory to /remotedir/
>       [ftp] getting files fileset: Setup scanner in dir /myproject/target with patternSet{ includes: [**/*.*] excludes: [] }
>       [ftp] 0 files retrieved
>       [ftp] disconnecting

I'm able to download this dump with FileZilla on myserver/remotedir/ (in an anonymous way). When I purposely try a wrong remotedir it warns me correctly ("550 Failed to change directory.") so I guess there is no connection problem.


Solution

  • I found a way to make it works! Referring to Ant manual, I'm using passive attribute in Ant FTP Task.

    If you can connect but not upload or download, try setting the passive attribute to true to use the existing (open) channel, instead of having the server try to set up a new connection.

    And here's the thing in pom.xml :

    <target>
        <ftp action="get" 
         server="myserver" 
         remotedir="/remotedir"
         userid="anonymous" 
         password="anonymous" 
         verbose="yes"
         passive="yes">
    
            <fileset dir="${project.build.directory}">
                <include name="**/*.*"/>
            </fileset>
        </ftp>
    </target>