How to escape @ in Ant SCP task

徘徊边缘 提交于 2019-12-04 05:05:26

问题


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.


回答1:


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?




回答2:


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


来源:https://stackoverflow.com/questions/12979503/how-to-escape-in-ant-scp-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!