如何通过FTPS使用Wagon Maven插件

时间:2019-11-27 17:23:13

标签: maven ftps maven-wagon-plugin wagon

我正在使用以下配置通过FTPS协议将文件上传到远程服务器:

<extensions>
    <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ftp</artifactId>
        <version>3.0.0</version>
    </extension>
</extensions>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>wagon-maven-plugin</artifactId>
    <version>1.0-beta-3</version>
    <configuration>
        <skip>true</skip>
        <url>ftps://username:password@ip_address</url>
        <fromDir>${project.build.directory}</fromDir>
        <toDir>.</toDir>
    </configuration>
    <executions>
        <execution>
            <id>upload</id>
            <phase>deploy</phase>
            <goals>
                <goal>upload</goal>
            </goals>
        </execution>
    </executions>
</plugin>

如果我在url参数中仅使用 FTP 而不是 FTPS ,则目标将成功执行并将数据发送到远程服务器,但是当我使用 FTPS 出于安全原因,出现以下错误:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:wagon-maven-plugin:1.0-beta-3:upload (default-cli) on project XXX: The parameters 'url' for goal org.codehaus.mojo:wagon-maven-plugin:1.0-beta-3:upload are missing or invalid
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginParameterException: The parameters 'url' for goal org.codehaus.mojo:wagon-maven-plugin:1.0-beta-3:upload are missing or invalid
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:641)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:594)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:121)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)

'

2 个答案:

答案 0 :(得分:1)

我使用以下配置解决了该问题:

Pom.xml:

 <extensions>
    <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ftp</artifactId>
        <version>3.0.0</version>
    </extension>
</extensions>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>wagon-maven-plugin</artifactId>
    <version>1.0-beta-3</version>
    <configuration>
        <serverId>serverid</serverId>
        <skip>true</skip>
        <url>ftps://ip_address:port</url>
        <fromDir>${project.build.directory}</fromDir>
        <toDir>.</toDir>
    </configuration>
    <executions>
        <execution>
            <id>upload</id>
            <phase>deploy</phase>
            <goals>
                <goal>upload</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Settings.xml:

   <server>
        <id>serverid</id>
        <username>XXXXXX</username>
        <password>XXXXXX</password>
        <configuration>
            <endpointChecking>false</endpointChecking>
            <securityProtocol>TLS</securityProtocol> 
            <implicit>true</implicit>
            <passiveMode>true</passiveMode>
        </configuration>
    </server>

谢谢!

答案 1 :(得分:0)

我没有能力在我的环境中测试答案,但似乎Wagon通过FTP提供程序支持FTPS模式。

documentation指出,为此,您应将securityProtocol配置为FTPS,因为默认值为TLS。

// settings.xml
<server>
    <id>ftp.server.id</id>
    <username>username</username>
    <password>password</password>
    <configuration>
         ....
         <securityProtocol>FTPS</securityProtocol>   <-- !!!
    </configuration>
</server>