我使用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/