ANT.SCP不支持从远程服务器复制到远程服务器的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的工作正常。现在,就我而言,本地目录将有 @。因此,我正在弄清楚如何逃脱这个角色。

根据SCP任务上的蚂蚁文档,在路径中具有@字符时使用localToDir而不是toDir

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

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

相关内容

最新更新