Ftp client cannot transfer file using IPV6

3.8k Views Asked by At

I am writing java code to send file through ftp as followed. The server that i used is FileZilla Server software at localhost.

    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);
    }
}

The problem is i can only send through IPV4 but not using IPv6. The java exeption is

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)

and the message in the file zilla server is

(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 ([email protected])
(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

Can any 1 help how to make it possible to send using IPV6.

Note : I already have IPV6 in my local.

1

There are 1 best solutions below

0
On

That EPRT command is bogus, it is requesting the server connect to an unspecified IPv4 address.

It might work better with a the localhost address ::1, or a global address, rather than a link-local address.