无法从外部 IP 向 proftpd 服务器传输文件
我正在制作一个与我的 ProFtpd 服务器配合使用的基本 FTP 传输应用程序。
在本地网络上,以下代码有效。但是,当我使用此代码并尝试通过外部 IP 连接时(是的,我将 IP 更改为我的外部 IP),我收到错误:
sun.net.ftp.FtpProtocolException:PORT:500 非法 PORT 命令,EPSV ALL 生效
另外,在浏览器中连接到 ftp 服务器会导致外部 IP 出现一两分钟的延迟,但我不知道是否是这样有关的。
这是我的代码:
URL url=new URL("ftp://"+username+":"+password+"@"+ip+path+recipient+"/"+sendMe.getName());
URLConnection con=url.openConnection();
System.out.println("connected");
FileInputStream input=new FileInputStream(sendMe);
BufferedOutputStream output=new BufferedOutputStream(con.getOutputStream());
System.out.println("output Stream");
int c;
int size=0;
TransferDialog transfer=new TransferDialog("0 bytes processed");
while ((c = input.read()) != -1) {
output.write(c);
size++;
transfer.changeText(size+" bytes processed");
System.out.println(size);
}
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
System.out.println("Uploaded");
运行时,会出现错误而不是“输出流”消息。任何帮助或建议表示赞赏!
I'm making a basic FTP transfer app that works with my ProFtpd server.
On the local network, the following code works. However, when I use this code and try to connect by external IP, (yes, I changed the IP to my external ip) I get the error:
sun.net.ftp.FtpProtocolException: PORT :500 Illegal PORT command, EPSV ALL in effect
In addition, the connection to ftp server in a browser causes a minute or two delay from the external IP, but I don't know if that is related.
Here's my code:
URL url=new URL("ftp://"+username+":"+password+"@"+ip+path+recipient+"/"+sendMe.getName());
URLConnection con=url.openConnection();
System.out.println("connected");
FileInputStream input=new FileInputStream(sendMe);
BufferedOutputStream output=new BufferedOutputStream(con.getOutputStream());
System.out.println("output Stream");
int c;
int size=0;
TransferDialog transfer=new TransferDialog("0 bytes processed");
while ((c = input.read()) != -1) {
output.write(c);
size++;
transfer.changeText(size+" bytes processed");
System.out.println(size);
}
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
System.out.println("Uploaded");
When this runs, the error occurs instead of the "output stream" message. Any help or suggestions is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎正在尝试通过外部 IP 建立活动 FTP 连接,当中间可能有防火墙。您需要启动一个被动连接,而不是旨在处理防火墙等(因为所有连接都是客户端在被动模式下发起的)。
当您在内部执行此操作时,此方法有效,因为您的客户端和服务器之间没有防火墙。请记住,防火墙(在其默认配置中)会阻止所有非客户端发起的 TCP 连接。
It looks like you're trying to make an Active FTP connection through your external IP, when there are presumably firewalls in between. You need to initiate a Passive connection instead which was designed to deal with firewalls and such (since all connections are client-initiated in passive mode).
This worked when you did it internally because there were no firewalls between your client and the server. Keep in mind firewalls (in their default configuration) block all non-client initiated TCP connections.