【问题标题】:ant.scp fails with Copying from a remote server to a remote server is not supported for local destinationant.scp 失败,本地目标不支持从远程服务器复制到远程服务器
【发布时间】:2019-07-12 00:06:19
【问题描述】:

我使用 gradle 将文件从远程机器复制到本地机器。以下是sn-p。

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

在 sn-p 之上,在 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 工作得很好。现在,就我而言,本地目录将有@。所以,我在想,如何逃脱这个角色。

【问题讨论】:

    标签: gradle groovy ant scp


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-09
      • 1970-01-01
      • 2014-09-11
      • 2020-11-17
      • 2010-09-09
      • 1970-01-01
      • 2014-11-18
      • 2018-02-15
      相关资源
      最近更新 更多