How to escape # in username in ant scp task [duplicate] - ant

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=""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"/>
<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.

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?

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

Related

What is this build.xml doing?

I am learning build.xml and am confused by the following code:
<macrodef name="a-test">
<attribute name="port" default="${PORT}"/> #1
<junit printsummary=...
<env key="PORT" value="#{port}" /> #2
...
when I run java with commandLine including -DPORT=8080 and then in java code I get port value 8080 by calling
String port = System.getenv(PORT).
What is the above build.xml doing? So far I know $ is to represent a property while # is to represent an attribute. Besides, the above code is the only place where PORT and port appear. What happens here so that port value are finally obtained in java code? Thanks.
The other question, what is the difference btw. using "env key" and using "sysproperty"? according to http://etutorials.org/Programming/Java+extreme+programming/Chapter+3.+Ant/3.6+Passing+Arguments+to+a+Buildfile/
sysproperty can be use to parse argument -D to java code, while env key is used to do the same thing right? Thanks.
Is there any detailed document about build.xml? the one I google from internet describer things so briefly.
What you see is macrodef in ant. There will be another place in build.xml(or other build.xml) where this is called by like
<a-test port=<value> ..

SCP / SSHEXEC - number of connection attempts

I am using scp task followed by sshexec in my ant build.xml. I derive the value for password from a Password field on the screen. The user doesnt have the ability to check if its the right password or not until the task completes successfully.
As a result, if the entered password is incorrect, does Scp / sshexec retry to connect? Is there any handle to limit the number of connection retries?
The sshexec and scp tasks use Java Secure Channel JSch, see ant manual library dependencies.
I had a similiar problem, as JSch tries to authenticate 6 times configured in the com.jcraft.jsch.JSch Class. When wrong password was used, the user account got locked.
Simply patched the com.jcraft.jsch.JSch Class like this :
from :
config.put("MaxAuthTries", "6");
to :
config.put("MaxAuthTries", "3");
Means JSch will only try 3 times to authenticate.
-- Edit after comment --
Download JSch release zip here - the latest version is 0.1.51
Unzip
Open jsch-0.1.51/src/main/java/com/jcraft/jsch/JSch.java
Change line 124
from
config.put("MaxAuthTries", "6");
to
config.put("MaxAuthTries", "3");
Save
Run jsch-0.1.51/build.bat or build.sh according to your OS
Use jsch-0.1.51/dist/lib/jsch-0.1.5.jar
Here a solution which does not require you to manually patch and rebuild the JSch library.
In order to limit the retry count to 1, just add the following script snippet either at the beginning of your Ant script, or before invoking scp and sshexec tasks, e.g.:
<script language="javascript"> <![CDATA[
com.jcraft.jsch.JSch.setConfig("MaxAuthTries", "1");
]]> </script>
<sshexec host="..." username="..." password="..." command="..."/>
You'll need JSch 0.1.46 or higher! I tested with Ant 1.9.4 and JSch 0.1.51 / 0.1.52.

Openbravo ant build fails

I am trying to setup openbravo on eclipse environment with the above URL.
Development stack setup is done successfully. (ANT, Java, Postgresql)
At the openbravo source directory when i apply the command
ant install.source
Build failure due to errors -
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/build.xml:480: The following error occurred while executing this line:
480 <ant dir="${base.src}" target="compile.complete.development" inheritAll="true" inheritRefs="true" />
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/src/build.xml:874: The following error occurred while executing this line:
874 <jvmarg line="${env.CATALINA_OPTS}" />
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/src/build.xml:880: Directory
880 <jvmarg value="-Djava.io.tmpdir=${env.CATALINA_BASE}/temp" />
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not successful for an unknown reason
Any help would be appreciated. Thanks.
Sounds like a permission problem.
See the related section 'Permission issues' in openbravo wiki
EDIT
for the remaining issues, i believe the properties base.src, CATALINA_OPTS and CATALINA_BASE are not set properly. Check this via :
<echo>
$${base.src} => ${base.src}
$${env.CATALINA_OPTS} => ${env.CATALINA_OPTS}
$${env.CATALINA_BASE} => ${env.CATALINA_BASE}
</echo>
or simply output all available properties use :
<echoproperties/>
also consider, before using ${env.whatever} you need to use :
<property environment="env"/>
before !
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not successful for an unknown reason
Give the permission to webapps folder
sudo chmod -R 777 /var/lib/tomcat6/webapps/
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not
successful for an unknown reason
it seem permission problem. It is important to always us the correct user account to start / stop tomcat!
Conceptually there are two user accounts involved in working with Openbravo:
command-line user used to work with files & compile Openbravo
user account used by Apache Tomcat service
There are several overlapping areas in which one of the accounts needs to access and modify files from the other account in both directions.
To avoid any problems Openbravo strongly recommends to run Apache Tomcat services with the same user account which is used on command line. As that way the above topic will be perfectly solved easily.
source: http://wiki.openbravo.com/wiki/Installation/Custom/Apache_Tomcat

How to escape # in Ant SCP task

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=""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"/>
<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.
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?
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

My ant signjar task seems to be changing my password

When I try to sign a jar with this line:
jarsigner -storetype pkcs12 -keystore cert_comodo.pfx MyJar.jar "le-01234567-0123-0123-0123-0123456789ab"
it prompts me for my password, and everything works fine. When I try to sign it with this ant target:
<target name="sign_jars" depends="obfuscated_jar">
<signjar
keystore="cert_comodo.pfx"
alias="le-01234567-0123-0123-0123-0123456789ab"
storepass="A, pa$$." <Not my real password or alias, btw>
storetype="pkcs12">
<path>
<fileset dir="." includes="*.jar" />
</path>
</signjar>
</target>
I get this error:
[signjar] jarsigner error: java.lang.RuntimeException: keystore load: failed t
o decrypt safe contents entry: javax.crypto.BadPaddingException: Given final blo
ck not properly padded
Which is the same error I get if I mistype my password.
Are the $ characters in my password being modified by Ant somehow? Is there a way I can trick ant into letting me type my password interactively? Thanks!
The problem is most likely due to ant seeing $$ as an escaped single $, thus passing the actual password string as A, pa$ to jarsigner. If the problem is still relevant, try changing the password to A, pa$$$$ for 2 $s to be escaped.
Some additional documentation from Apache Antâ„¢ Task Design Guidelines:
... Ant 1.5 passes the single dollar sign "$" through in strings; Ant 1.4 and before would strip it. To get this fix in we first had to write the test suite to expose current behaviour, then change something so that single "$" was passed through, but double "$$" got mapped to "$" for backwards compatibility.

Resources