You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Gareth Kelly <Ga...@davy.ie> on 2006/05/09 13:02:07 UTC

ANT SCP Via a Java App

Hi,
Not sure if this is the correct mailing list, but hopefully someone can help
me.
I have been using the ant and ant-jsch.jar in a java app to scp files from
one machine to another.
 
Works fine when passing in username and password.
I set up a trusted connection by creating a public/private key pair and
appending the identity.pub to the remote authorized_keys.
Now I can scp a file from the command line without a password.
 
But when I try to do this from the java app, i get the following error:
 
neither password nor passphrase for user nettrade has been given.  Can't
authenticate.
        at
org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:166)
        at GetReutersKey.scpFile(GetReutersKey.java:346)
        at GetReutersKey.main(GetReutersKey.java:65)
Caused by: neither password nor passphrase for user nettrade has been given.
Can't authenticate.
        at
org.apache.tools.ant.taskdefs.optional.ssh.Scp.parseUri(Scp.java:254)
        at
org.apache.tools.ant.taskdefs.optional.ssh.Scp.upload(Scp.java:223)
        at
org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:155)
        ... 2 more
--- Nested Exception ---
neither password nor passphrase for user nettrade has been given.  Can't
authenticate.
        at
org.apache.tools.ant.taskdefs.optional.ssh.Scp.parseUri(Scp.java:254)
        at
org.apache.tools.ant.taskdefs.optional.ssh.Scp.upload(Scp.java:223)
        at
org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:155)
        at GetReutersKey.scpFile(GetReutersKey.java:346)
        at GetReutersKey.main(GetReutersKey.java:65)

This is my code:
 
            Scp scpConnection = new Scp();
            Project project = new Project();
            scpConnection.setFile(aSFile);
            scpConnection.setTrust(true);
            scpConnection.setTodir("nettrade@laois <ma...@laois>
:" + aSDir);
            scpConnection.setProject(project);
            scpConnection.execute();

 
Any ideas?
 
Thanks,
Gareth


The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any other action taken or any views, opinions or advice contained in this e-mail are those of the sending individual and not necessarily those of the firm. It is possible for data transmitted by e-mail to be deliberately or accidentally corrupted or intercepted. For this reason where the communication is by e-mail, J&E Davy does not accept any responsibility for any breach of confidence which may arise from the use of this medium. If you have received this e-mail in error please notify us immediately at mailto:helpdesk@davy.ie and delete this e-mail from your system.


Re: ANT SCP Via a Java App

Posted by Atsuhiko Yamanaka <ym...@jcraft.com>.
Hi,

2006/5/9, Gareth Kelly <Ga...@davy.ie>:
> Works fine when passing in username and password.
> I set up a trusted connection by creating a public/private key pair and
> appending the identity.pub to the remote authorized_keys.

The internal ssh client can not understand ssh1 public/private key.

So, generate key pair by "ssh-keygen -t rsa" or "ssh-keygen -t dsa" and
you will have key-pair like "id_dsa, id_dsa.pub" or "id_rsa,id_rsa.pub".
And, you have to set its private key explicitly with setKeyfile method.

>            Scp scpConnection = new Scp();
>            Project project = new Project();
>            scpConnection.setFile(aSFile);

              scpConnection.setKeyfile("/home/nettrade/.ssh/id_dsa");

then, you must set something as a passphrase even if it is not
encrypted, because
there is a bug.

              scpConnection.setPassphrase("");

>            scpConnection.setTrust(true);
>            scpConnection.setTodir("nettrade@laois <ma...@laois>
> :" + aSDir);
>            scpConnection.setProject(project);
>            scpConnection.execute();

Dear developers, to resolve above bug, following lines in 
org/apache/tools/ant/taskdefs/optional/ssh/Scp.java

        if (getUserInfo().getPassword() == null
            && getUserInfo().getPassphrase() == null) {
            throw new BuildException("neither password nor passphrase for user"
                                     + getUserInfo().getName() + " has been "
                                     + "given.  Can't authenticate.");
        }

should be

        if (getUserInfo().getPassword() == null
            && (getUserInfo().getPassphrase() == null &&
getUserInfo().getKeyfile()==null)) {
            throw new BuildException("neither password nor passphrase for user"
                                     + getUserInfo().getName() + " has been "
                                     + "given.  Can't authenticate.");
        }

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org