gradle - ant.scp失败,本地目标不支持从远程服务器复制到远程服务器

标签 gradle groovy ant scp

我使用gradle将文件从远程计算机复制到本地计算机。以下是代码段。

    ant.scp(file: "${userName}:${pwd}@${hostName}:${remoteFileAbsPath}", todir: localFileDirPath, trust: "true")

以上代码段在Windows Shell中工作正常,但在ubuntu Shell中失败,并出现以下错误。
Caused by: : Copying from a remote server to a remote server is not supported.
at org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:229)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:77)...

来自终端的常规scp可以正常工作。只有ant.scp才会在Linux环境中失败。 taskdef声明为ant.taskdef(name: 'scp', classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp', classpath:somepath)。导致问题的任何指针/引用将很有用。

在调试时,我只是发现变量localFileDirPath具有@符号。例如,localDir名称为“sample @ localDirectory”。现在,我猜想ant.scp假定“sample @ localDirectory”是另一个远程服务器-由于该错误消息完全有意义。当我使用不带@的另一个localFileDirPath进行测试时,ant.scp可以正常工作。现在,在我的情况下,本地目录将具有@。因此,我正在研究如何逃避此角色。

最佳答案

根据ant documentation on the scp task,当路径中有localToDir字符时,请使用toDir而不是@:

  ant.scp(file: "${userName}:${pwd}@${hostName}:${remoteFileAbsPath}", localtodir: localFileDirPath, trust: "true")

使用localToDir,您无需转义@字符,只需按原样发送即可。

关于gradle - ant.scp失败,本地目标不支持从远程服务器复制到远程服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54750112/

相关文章:

java - 如何使用 Spring Boot 将 Groovy 类与 Java 类一起运行

gradle - 如何从字符串或类路径资源创建 RegularFileProperty?

eclipse - Eclipse 中的 Grails 2.2.0 支持

java - 在 groovy/java 中实现复制或克隆

java - 在 Apache Ant 中查找调用(或父)目标

gradle - 如何从命令行获取gradle属性?

android - 获取 :app:processDebugResources while flutter run 的一些未知错误

java - 如何在 SoapUI 中明智地比较两个 XML 文件?

java - Ant else 条件执行

ant - Ivy :publish use the [classifier] attribute 怎么样