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

问题描述 投票:0回答:1

我使用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工作正常。现在,在我的情况下,本地目录将有@。所以,我正在弄清楚,如何逃避这个角色。

gradle groovy ant scp
1个回答
1
投票

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

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

localToDir你不需要逃脱@角色,只需按原样发送。

© www.soinside.com 2019 - 2024. All rights reserved.