Apache vfs/jsch sftp 发生算法协商失败。这种情况往往由于远程 SFTP 服务器配置过于严格而导致。可以尝试修改本地代码以限制使用的算法,或者联系远程服务器管理员进行配置修改。
代码示例:
public static void main(String[] args) {
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession("username", "hostname", 22);
session.setPassword("password");
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp");
channelSftp.connect();
// 限制使用的算法
Properties config = new Properties();
config.put("cipher.s2c", "aes128-ctr,aes192-ctr,aes256-ctr");
config.put("cipher.c2s", "aes128-ctr,aes192-ctr,aes256-ctr");
channelSftp.setConfig(config);
// do SFTP operations...
channelSftp.disconnect();
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
}
}