FTP 上传文件错误代码=425,消息=无法打开数据连接

发布于 2025-01-07 14:17:28 字数 1117 浏览 1 评论 0原文

我使用 ftp4j 通过小程序进行 FTP 连接来上传文件。 从服务器上,我已经打开端口 27 的 FTP 站点,targetURL = 本地 IP 地址为 192.168.x.xxx,并授予用户名 FTPUser、密码 xxxx 的访问权限。

FTPClient client = new FTPClient();
client.connect(targetURL, port);
client.setType(client.TYPE_BINARY);
client.login(user, password);
fis = new FileInputStream(targetFile);
client.upload(targetFile);

它在内部网络中通过小程序成功连接并上传文件

但是,当我尝试使用外部网络进行测试时,路由器已经配置为使用 NAT 将本地 IP 转换为外部 IP:175.136.xxx.xxx,端口为 47027(已测试)使用命令的 FTP 连接),我收到此错误消息:

user: FTPUser, password: xxxx port 47027
network: Connecting http://175.136.xxx.xxx:47027/  with proxy=DIRECT
network: Connecting http://175.136.xxx.xxx:20459/  with proxy=DIRECT
it.sauronsoftware.ftp4j.FTPException [code=425, message= Can't open data connection.]
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2658)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2539)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2410)

从错误日志来看,它尝试通过端口 47027 建立连接,然后更改为 20459 (我这样做不知道从哪里来)。

我可以看到该文件是在服务器 FTP 站点中创建的,但大小为 0 字节。

任何人都知道这种情况出了什么问题?

I'm using ftp4j for FTP connection through applet to upload file.
From server, I already open FTP site with port 27, targetURL = local IP address is 192.168.x.xxx, and grant access for user name FTPUser, password xxxx.

FTPClient client = new FTPClient();
client.connect(targetURL, port);
client.setType(client.TYPE_BINARY);
client.login(user, password);
fis = new FileInputStream(targetFile);
client.upload(targetFile);

It connects and uploads file successfully through applet, within internal network

However, when I try to test with external network, router is already configured by using NAT to translate the local IP to external IP: 175.136.xxx.xxx with port 47027 (already tested the FTP Connection using command), I got this error message:

user: FTPUser, password: xxxx port 47027
network: Connecting http://175.136.xxx.xxx:47027/  with proxy=DIRECT
network: Connecting http://175.136.xxx.xxx:20459/  with proxy=DIRECT
it.sauronsoftware.ftp4j.FTPException [code=425, message= Can't open data connection.]
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2658)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2539)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2410)

As from the error log, it tried to establish the connection through port 47027, then after that change to 20459 (that I do not know where it comes from).

I can see the file is created in the server FTP site, but with 0 byte.

Anyone knows what's wrong with this situation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝在阴天搁浅。 2025-01-14 14:17:28

请改用被动模式。您这边可能阻塞了端口。

Use passive mode instead. Your side might be blocking the port.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文