Ftp客户端无法使用IPV6传输文件

时间:2011-10-18 06:50:33

标签: java ipv6 ftp-client ftp-server

我正在编写java代码,通过ftp发送文件,如下所示。我使用的服务器是localhost上的FileZilla Server软件。

    public static void main(String[] args) {
    try {
        String host = "fe80::21a:a0ff:fe8d:fe63"; //No problem if ipv4
        int port = 1998;
        String username = "joe";
        String password = "123";
        String directory = "D:/ftp_share";
        File fileToTransfer = new File("D:/RND/samplefile.txt");
        String fileName = fileToTransfer.getName();
        FTPClient ftp = new FTPClient();
        ftp.connect(host, port);
        ftp.login(username, password);
        FileInputStream in = new FileInputStream(fileToTransfer);
        if (!(directory == null || "".equals(directory))) {
            ftp.changeWorkingDirectory(directory);
        }
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.appendFile(fileName, (InputStream) in);
        System.out.println("File " + fileName + " succesfully sent via ftp to " + host + " at port " + port);

    } catch (SocketException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

问题是我只能通过IPV4发送但不能使用IPv6。 java exeption是

org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received.  Server closed connection.
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:360)
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:290)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:474)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:547)
    at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:680)
    at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:551)
    at org.apache.commons.net.ftp.FTPClient.appendFile(FTPClient.java:1765)
    at rnd.Main.main(Main.java:44)

并且文件zilla服务器中的消息是

(000018)10/18/2011 14:46:39 PM - (not logged in) (fe80::21a:a0ff:fe8d:fe63)> Connected, sending welcome message...
(000018)10/18/2011 14:46:39 PM - (not logged in) (fe80::21a:a0ff:fe8d:fe63)> 220-FileZilla Server version 0.9.39 beta
(000018)10/18/2011 14:46:39 PM - (not logged in) (fe80::21a:a0ff:fe8d:fe63)> 220-written by Tim Kosse (Tim.Kosse@gmx.de)
(000018)10/18/2011 14:46:39 PM - (not logged in) (fe80::21a:a0ff:fe8d:fe63)> 220 Please visit http://sourceforge.net/projects/filezilla/
(000018)10/18/2011 14:46:39 PM - (not logged in) (fe80::21a:a0ff:fe8d:fe63)> USER joe
(000018)10/18/2011 14:46:39 PM - (not logged in) (fe80::21a:a0ff:fe8d:fe63)> 331 Password required for joe
(000018)10/18/2011 14:46:39 PM - (not logged in) (fe80::21a:a0ff:fe8d:fe63)> PASS ***
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> 230 Logged on
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> CWD D:/RND/ftp_share
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> 550 CWD failed. "/D:/RND/ftp_share": directory not found.
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> TYPE I
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> 200 Type set to I
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> EPRT |1|0.0.0.0|2885|
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> 200 Port command successful
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> APPE jawapannya.txt
(000018)10/18/2011 14:46:39 PM - joe (fe80::21a:a0ff:fe8d:fe63)> 421 Can't create socket

任何1可以帮助如何使用IPV6发送。

注意:我的本地已经有IPV6了。

1 个答案:

答案 0 :(得分:0)

该EPRT命令是假的,它正在请求服务器连接到未指定的IPv4地址。

使用localhost地址:: 1或全局地址而不是链接本地地址可能会更好。