How to escape @ in Ant SCP task

2019-02-28 12:23发布

I would like to ask you for some help. How can I use an scp task when my username contains an @ sign?

I tried to escape the character in many ways but it isn't working. In the following example, my username is 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"/>

But the output is always the same:

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

Please, is there anyway to force the task to parse this string correctly? Thank you very much.

By the way, I don't know why but with my current provider it is impossible to create a username without appending the hostname.

2条回答
迷人小祖宗
2楼-- · 2019-02-28 13:06

I use the SCP task in my build.xml and it's form looks like this:

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

Looking at the source of the SCP Task at the function parseUri(String uri) (line 370) it appears that the task can support a username with a @ symbol. The restrictions appear to be with paths that have a : or @ in them as seen by this comment:

// 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)

The code doesn't seem to support this comment (as pointed out by martin clayton). You can also see the error you are referring which is triggered when the password or the keyfile is missing. Maybe the combination of a password in user:password@host:/path notation and a username with an @ is causing problems?

查看更多
我命由我不由天
3楼-- · 2019-02-28 13:10

Present ant version -1.9.4 operating system:-16.04 Ubuntu did not work.

Changed to 1.9.3 and pointed to /usr/bin/ant ssh was successful observation:

16.04 and ant 1.9.3 is working
14.04 ant 1.9.4 is working
查看更多
登录 后发表回答