【问题标题】:How to escape @ in Ant SCP task如何在 Ant SCP 任务中转义 @
【发布时间】:2012-10-10 09:04:33
【问题描述】:

我想请你帮忙。当我的用户名包含 @ 符号时,如何使用 scp 任务?

我尝试以多种方式转义该角色,但它不起作用。在以下示例中,我的用户名是 user@host.com

<scp file="test.txt" todir="&quot;user@host.com&quot;:password@ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="'user@host.com':password@ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="user\@host.com:password@ftp.host.com:/" trust="true" sftp="true"/>

但是输出总是一样的:

neither password nor keyfile for user "user has been given.  Can't authenticate. 

请问,是否有强制任务正确解析此字符串?非常感谢。

顺便说一句,我不知道为什么,但是对于我当前的提供商,如果不附加主机名就不可能创建用户名。

【问题讨论】:

    标签: ant escaping sftp scp


    【解决方案1】:

    我在 build.xml 中使用 SCP 任务,它的形式如下所示:

    <scp file="package/ROOT.war" todir="user@example.com:~" trust="true" password="${password}"/>
    

    查看函数parseUri(String uri)(第370行)中的source of the SCP Task,似乎该任务可以支持带有@符号的用户名。正如此评论所见,这些限制似乎与路径中包含 : 或 @ 的路径有关:

    // user:password@host:/path notation
    // everything upto the last @ before the last : is considered
    // password. (so if the path contains an @ and a : it will not work)
    

    代码似乎不支持此注释(如指出 martin clayton)。您还可以看到当密码或密钥文件丢失时触发的错误。也许user:password@host:/path 符号中的密码和带有@ 的用户名的组合会导致问题?

    【讨论】:

    • 您好,谢谢您的回答。我确定我的用户名包含@ 符号。我现在只有 Windows。但是当我使用任何 GUI 应用程序(如 WinSCP 或 TotalCommander)时,连接工作正常。是的,我必须使用 SFTP 连接而不是 SCP。我阅读了文档(ant.apache.org/manual/Tasks/scp.html),密码可以双向传递。但两种方式都行不通
    • 当我通过 TC 连接时,我在标题中看到:user@host.com@ftp.host.com
    • 这个线程 iprodeveloper.com/forums/aft/53169 讨论了与旧版本的 scp 和 sftp 以及其中带有 @ 符号的用户名不兼容。他们提供使用 \@ 转义或升级服务器。这些有帮助吗?
    • 感谢您的评论。我找到了这个论坛并尝试了这些转义的可能性(有问题提到),但它们不起作用。我认为我在服务器端没有问题。我可以与其他客户联系。我认为是 Ant scp 客户端解析它不正确。现在我得到这个错误: java.net.UnknownHostException: host.com@ftp.host.com ,但主机只是 ftp.host.com。
    • 对我来说它看起来像一个 Ant 错误。您引用的评论上方的行显示了错误 - 它假定 uri 中的第一个冒号将始终是 before 第一个 @,但是当 @ 出现在用户名中时,情况并非如此。 if 中的替代逻辑也不支持这种情况。需要稍微改写。
    【解决方案2】:

    目前的ant版本-1.9.4操作系统:-16.04 Ubuntu不起作用。

    改成1.9.3并指向/usr/bin/ant ssh成功 观察:

    16.04 and ant 1.9.3 is working
    14.04 ant 1.9.4 is working
    

    【讨论】:

      猜你喜欢
      • 2011-09-15
      • 2023-03-09
      • 2014-10-19
      • 1970-01-01
      • 2011-02-19
      • 2012-10-16
      • 2011-11-17
      • 2011-07-02
      • 2011-01-23
      相关资源
      最近更新 更多