我是新手并尝试使用以下代码建立SCP连接:
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();
}
我得到以下例外:
*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
我在项目中放置了以下所有JAR文件: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