无法从外部IP

无法从外部IP

问题描述:

我正在与我的ProFTPD服务器工作的基本FTP传输的应用程序传输文件的ProFTPD服务器。无法从外部IP

在本地网络中,下面的代码工作。然而,当我使用此代码,并尝试通过外部IP连接,(是的,我改变了IP到我的外部IP),我得到的错误:

sun.net.ftp.FtpProtocolException: PORT :500 Illegal PORT command, EPSV ALL in effect

此外,连接到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"); 

当这个运行时,发生了错误,而不是“输出流”的消息。任何帮助或建议表示赞赏!

+0

这是不是一个真正的java的问题,这是关于如何配置你的FTP服务器正常工作,更对serverfault.com问题(减去的Java位)。 – skaffman 2012-02-09 15:39:00

它看起来像你想通过你的外部IP作出Active FTP connection,当有可能与防火墙英寸你需要启动Passive connection,而不是它的目的是对付防火墙等(因为所有的连接都是客户端发起的在被动模式下)。

当你做到这一点内部,因为您的客户端和服务器之间没有防火墙。请记住,防火墙(以其默认配置)将阻止所有非客户端启动的TCP连接。

+0

谢谢!你知道如何编辑代码以将其从活动连接改为被动连接吗? – J3RN 2012-02-09 15:46:59

+0

@Jon你没有向我们展示那部分代码,但我相信你可以通过查找来找出它。这应该让你朝着正确的方向前进。 – 2012-02-09 15:48:51

+0

@乔恩:见http://*.com/questions/2282776/setting-ftp-active-passive-mode-with-java-urlconnection – beny23 2012-02-09 15:49:53