2

I'm new to this and trying to establish an SCP connection using the below code:

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("Hello world");
    org.apache.tools.ant.taskdefs.optional.ssh.Scp scp = new Scp();
    int portSSH = 22;
    String srvrSSH = "xx.xx.xx.xx";
    String userSSH = "username"; 
    String pswdSSH = "password";
    String localFile = "C:\\xxx\\xxx.txt";
    String remoteDir = "home/xxx/exports/xxx";
    scp.setPort( portSSH );
    scp.setLocalFile( localFile );
    scp.setTodir( userSSH + ":" + pswdSSH + "@" + srvrSSH + ":" + remoteDir );
    scp.setProject( new Project() );
    scp.setTrust( true );
    scp.execute();
    }

And i'm getting the below exception:

*Hello world
Exception in thread "main" com.jcraft.jsch.JSchException: Algorithm negotiation fail
       at org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:245)
       at com.scpconnection.SCPConnection.main(SCPConnection.java:31)
Caused by: com.jcraft.jsch.JSchException: Algorithm negotiation fail
       at com.jcraft.jsch.Session.receive_kexinit(Session.java:540)
       at com.jcraft.jsch.Session.connect(Session.java:288)
       at com.jcraft.jsch.Session.connect(Session.java:145)
       at org.apache.tools.ant.taskdefs.optional.ssh.SSHBase.openSession(SSHBase.java:223)
       at org.apache.tools.ant.taskdefs.optional.ssh.Scp.upload(Scp.java:324)
       at org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:226)
       ... 1 more

I have all the below JAR files placed in my project: ant-1.7.0.jar, ant-jsch-1.8.1.jar, ant-launcher-1.7.0.jar, jsch-0.1.48-sources.jar, com.jcraft.jsch_0.1.31.jar

Tamalika Biswas
  • 101
  • 1
  • 2
  • 5
  • Thanks, but i'm getting the same exception on adding the 0.1.54 jar, where do we see the JSch log file? – Tamalika Biswas Nov 02 '17 at 07:39
  • @MartinPrikryl thanks.. This is what the log prints:INFO: Connecting to xx.xx.xx.xx port 22 INFO: Connection established INFO: Remote version string: SSH-2.0-OpenSSH_7.4 INFO: Local version string: SSH-2.0-JSCH-0.1.31 INFO: SSH_MSG_KEXINIT received INFO: SSH_MSG_KEXINIT sent com.jcraft.jsch.JSchException: Algorithm negotiation fail – Tamalika Biswas Nov 02 '17 at 07:54
  • @MartinPrikryl thanks! it works. – Tamalika Biswas Nov 02 '17 at 13:00

0 Answers0