gpt4 book ai didi

java - 通过FTPS协议(protocol)发送文件到服务器

转载 作者:行者123 更新时间:2023-12-02 04:33:23 28 4
gpt4 key购买 nike

我正在创建一个生成 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

最佳答案

关于java - 通过FTPS协议(protocol)发送文件到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56563779/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com