使用 JSCH 创建 SFTP 时出现此错误。我正在尝试通过 sftp 连接到远程服务器以传输文件,但是在调用 connect 方法时出现以下错误。
java.lang.ExceptionInInitializerError
at javax.crypto.Cipher.getInstance(DashoA13*..)
at com.jcraft.jsch.jce.AES256CTR.init(AES256CTR.java:56)
at com.jcraft.jsch.Session.checkCipher(Session.java:2072)
at com.jcraft.jsch.Session.checkCiphers(Session.java:2049)
at com.jcraft.jsch.Session.send_kexinit(Session.java:592)
at com.jcraft.jsch.Session.connect(Session.java:286)
at com.jcraft.jsch.Session.connect(Session.java:162)
at scb.frame.runner.ServerSetup.contactServer(ServerSetup.java:56)
Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs
at javax.crypto.SunJCE_b.<clinit>(DashoA13*..)
... 34 more
Caused by: java.lang.SecurityException: Cannot locate policy or framework files!
at javax.crypto.SunJCE_b.i(DashoA13*..)
at javax.crypto.SunJCE_b.g(DashoA13*..)
at javax.crypto.SunJCE_b$1.run(DashoA13*..)
at java.security.AccessController.doPrivileged(Native Method)
... 35 more
我的连接代码:
String host = serverProperties.getProperty("Host");
String username = serverProperties.getProperty("Username");
String password = serverProperties.getProperty("Password");
JSch jsch = new JSch();
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Session session;
try {
session = jsch.getSession(username, host, 22);
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
sftpChannel.get(sourceFile,destFile);
Same Program 的命令行版本我可以毫无例外地运行!Jcraft[link] http://www.jcraft.com/jsch/examples/Sftp.java.html网站的 SFTP 示例也运行良好。