我正在创建一个生成 CSV 文件和一些 PDF 的应用程序。我希望我的应用程序通过 FTPS 协议(protocol)将这些文件发送到服务器。
我正在使用 Apache Commons Net FTP 库,当我未选中“使用 PORT P 时需要数据连接上的 TLS session 恢复”时,它工作得很好,但由于我启用了它,所以我无法发送我的文件。
出现错误:
450 数据连接的 TLS session 尚未恢复或 session 与控制连接不匹配
。
经过对这个网站的一些研究,我重写了 _prepareDataSocket_
以解决这个问题,但现在它只是在服务器上创建空文件。
这是我的重写函数:
@Override
protected void _prepareDataSocket_(final Socket socket) throws IOException {
if (socket instanceof SSLSocket) {
// Control socket is SSL
final SSLSession session = ((SSLSocket) _socket_).getSession();
if (session.isValid()) {
final SSLSessionContext context = session.getSessionContext();
try {
final Field sessionHostPortCache = context.getClass().getDeclaredField("sessionHostPortCache");
sessionHostPortCache.setAccessible(true);
final Object cache = sessionHostPortCache.get(context);
final Method method = cache.getClass().getDeclaredMethod("put", Object.class, Object.class);
method.setAccessible(true);
method.invoke(cache, String
.format("%s:%s", socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()))
.toLowerCase(Locale.ROOT), session);
method.invoke(cache, String
.format("%s:%s", socket.getInetAddress().getHostAddress(), String.valueOf(socket.getPort()))
.toLowerCase(Locale.ROOT), session);
} catch (NoSuchFieldException e) {
throw new IOException(e);
} catch (Exception e) {
throw new IOException(e);
}
} else {
throw new IOException("Invalid SSL Session");
}
}
}
这就是 FileZilla 服务器显示的内容: FileZilla Response
最佳答案
另一个论坛上的这个答案有帮助吗? http://forum.rebex.net/5673/450-error-connecting-to-ftp-requiring-explicit-ftp-over-tls
关于java - 通过FTPS协议(protocol)发送文件到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56563779/