You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

maven-antrun-plugin 1.4版本FTP无传输内容问题排查求助

问题诊断与解决

你的构建日志仅显示任务执行的开始和结束,却没有任何FTP相关的详细输出(比如服务器连接、文件传输记录),这说明Ant的ftp任务要么根本没被执行,要么执行时没找到符合条件的文件。下面是具体的排查和修复方案:

1. 缺失Ant FTP任务的依赖包

Ant的ftp属于可选任务,并不包含在Ant核心包(ant:1.9.1)中,必须额外引入ant-commons-net依赖——这个包是FTP任务的实现载体。你当前的配置只添加了Ant核心依赖,导致Ant无法识别ftp标签,直接跳过了这一步操作。

需要在maven-antrun-plugin的<dependencies>中补充以下依赖:

<dependency>
    <groupId>org.apache.ant</groupId>
    <artifactId>ant-commons-net</artifactId>
    <version>1.9.1</version>
</dependency>

注意版本要和你使用的Ant版本(1.9.1)保持一致,避免版本冲突。

2. 验证本地文件路径与文件存在性

先确认fileset配置的路径C:\Users\Michal\Downloads\web-framework下确实存在.txt文件:

  • 手动打开该目录检查文件是否存在
  • 也可以在Ant任务中添加echo输出,验证路径和文件匹配规则:
    <target>
        <!-- 添加echo任务确认文件列表 -->
        <echo message="本地目录匹配到的文件:"/>
        <fileset dir="C:\Users\Michal\Downloads\web-framework">
            <include name="*.txt"/>
        </fileset>
        <!-- 原FTP任务 -->
        <ftp action="send" server="10.132.30.179" remotedir="subsystems" userid="radio" password="oss" depends="yes" verbose="yes">
            <fileset dir="C:\Users\Michal\Downloads\web-framework">
                <include name="*.txt"/>
            </fileset>
        </ftp>
    </target>
    

重新执行mvn package,如果echo部分没有输出任何文件,说明路径或匹配规则有误。

3. 启用Debug日志排查细节

通过命令行添加日志参数,查看Ant任务执行的详细过程:

mvn package -X

-X会输出Debug级别的日志,你可以从中找到FTP任务的加载状态、服务器连接情况、文件匹配结果等信息,快速定位核心问题。

4. 检查FTP服务器的权限与目录

即使构建没有报错,也可能存在以下情况:

  • 用户radio没有服务器写入权限
  • 远程目录subsystems不存在
  • 本地文件没有读取权限

建议用手动FTP客户端(比如FileZilla)测试连接,验证上述权限和目录是否正常。

修复后的完整插件配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <id>ftp</id>
            <phase>package</phase>
            <configuration>
                <target>
                    <ftp action="send" server="10.132.30.179" remotedir="subsystems" userid="radio" password="oss" depends="yes" verbose="yes">
                        <fileset dir="C:\Users\Michal\Downloads\web-framework">
                            <include name="*.txt"/>
                        </fileset>
                    </ftp>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.9.1</version>
        </dependency>
        <!-- 新增FTP任务依赖 -->
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-commons-net</artifactId>
            <version>1.9.1</version>
        </dependency>
    </dependencies>
</plugin>

按照以上步骤排查修复后,重新执行mvn package,应该就能看到FTP传输的详细日志,文件也会正常上传到服务器了。

内容的提问来源于stack exchange,提问作者Fubundzer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:51:07