Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.6k views
in Java FTP by (240 points)
I want to connect to a FTP Server, in this case FileZilla Server, with Java. I've download edtFTPJ/free and I've been trying the examples that they sent in that package. Connecting to the server, deleting folder/files, renaming, creating folders works, but when I want to get the directory list, the connection gets closed. (This also happens with another library called FTP4J.) Here is the code:

package ftp_classes;

import com.enterprisedt.net.ftp.FileTransferClient;
import com.enterprisedt.net.ftp.FTPFile;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;

public class GetDirectoryListing {

    public static void main(String[] args) {

        String host = "localhost";
        String username = "user";
        String password = "password";

        // set up logger so that we get some output
        Logger log = Logger.getLogger(GetDirectoryListing.class);
        Logger.setLevel(Level.INFO);

        FileTransferClient ftp = null;

        try {
              com.enterprisedt.util.debug.Logger.setLevel(com.enterprisedt.util.debug.Level.DEBUG);
            // create client
            log.info("Creating FTP client");
            ftp = new FileTransferClient();

            // set remote host
            log.info("Setting remote host");
            ftp.setRemoteHost(host);
            ftp.setUserName(username);
            ftp.setPassword(password);

            // connect to the server
            log.info("Connecting to server " + host);
            ftp.connect();
            log.info("Connected and logged in to server " + host);

            log.info("Getting current directory listing");
            FTPFile[] files = ftp.directoryList(".");
            for (int i = 0; i < files.length; i++) {
                log.info(files[i].toString());
            }

            // Shut down client
            log.info("Quitting client");
            ftp.disconnect();

            log.info("Example complete");

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

}


here is the console output:

INFO [ftp_classes.GetDirectoryListing] 1 Jun 2012 14:05:00.151 : Setting remote host
INFO [ftp_classes.GetDirectoryListing] 1 Jun 2012 14:05:00.151 : Connecting to server localhost
DEBUG [FileTransferClient] 1 Jun 2012 14:05:00.151 : Configured client
DEBUG [FTPClient] 1 Jun 2012 14:05:00.159 : Connecting to localhost/127.0.0.1:21
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.175 : 220-FileZilla Server version 0.9.41 beta
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.175 : 220-written by Tim Kosse (Tim.Kosse@gmx.de)
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.177 : 220 Please visit http://sourceforge.net/projects/filezilla/
DEBUG [FileTransferClient] 1 Jun 2012 14:05:00.179 : Client connected
DEBUG [FileTransferClient] 1 Jun 2012 14:05:00.180 : Logging in
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.180 : ---> USER user
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.180 : 331 Password required for user
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.181 : ---> PASS ********
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.181 : 230 Logged on
DEBUG [FileTransferClient] 1 Jun 2012 14:05:00.181 : Logged in
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.181 : ---> TYPE I
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.182 : 200 Type set to I
INFO [ftp_classes.GetDirectoryListing] 1 Jun 2012 14:05:00.182 : Connected and logged in to server localhost
INFO [ftp_classes.GetDirectoryListing] 1 Jun 2012 14:05:00.182 : Getting current directory listing
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.189 : ---> SYST
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.189 : 215 UNIX emulated by FileZilla
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.194 : ---> PWD
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.194 : 257 "/" is current directory.
DEBUG [FTPClient] 1 Jun 2012 14:05:00.194 : setupDirDetails(.) returning: /
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.195 : ListenOnAllInterfaces=true
com.enterprisedt.net.ftp.ControlChannelIOException: Software caused connection abort: socket write error
    at com.enterprisedt.net.ftp.FTPControlSocket.writeCommand(FTPControlSocket.java:1020)
    at com.enterprisedt.net.ftp.FTPControlSocket.sendCommand(FTPControlSocket.java:997)
    at com.enterprisedt.net.ftp.FTPControlSocket.setDataPort(FTPControlSocket.java:813)
    at com.enterprisedt.net.ftp.FTPControlSocket.sendPORTCommand(FTPControlSocket.java:669)
    at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocketActive(FTPControlSocket.java:616)
    at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocket(FTPControlSocket.java:583)
    at com.enterprisedt.net.ftp.FTPClient.setupDataSocket(FTPClient.java:2648)
    at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3664)
    at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3756)
    at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:3583)
    at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:647)
    at ftp_classes.GetDirectoryListing.main(GetDirectoryListing.java:52)
DEBUG [FTPControlSocket] 1 Jun 2012 14:05:00.197 : ---> PORT 127,0,0,1,201,168


Can anyone help me? I really don't know why this is happening.

7 Answers

0 votes
by (162k points)
It sounds like a firewall might be killing the connection.
0 votes
by (240 points)
Why the firewall? I can create folders, delete files and do everything besides getting the directory listing. Why should the firewall just block that part? Mh.. :(
0 votes
by (162k points)
Because directory listings and transfers use a new connection that uses different ports to the commands.
0 votes
by (240 points)
When I use a filezilla ftp client instead, it does give me the directory listing. So the firewall isn't blocking that port I think. It has to do with the code then, but I don't know what is wrong.
0 votes
by (51.6k points)
Can you please post the FileZilla log?

- Hans (EnterpriseDT)
0 votes
by (240 points)
The filezilla server log when I connect with filezilla:
FileZilla Server version 0.9.41 beta
Copyright 2001-2012 by Tim Kosse (tim.kosse@filezilla-project.org)
Connecting to server...
Connected, waiting for authentication
Logged on
(000007)08.06.2012 11:13:29 - (not logged in) (::1)> Connected, sending welcome message...
(000007)08.06.2012 11:13:29 - (not logged in) (::1)> 220-FileZilla Server version 0.9.41 beta
(000007)08.06.2012 11:13:29 - (not logged in) (::1)> 220-written by Tim Kosse (Tim.Kosse@gmx.de)
(000007)08.06.2012 11:13:29 - (not logged in) (::1)> 220 Please visit http://sourceforge.net/projects/filezilla/
(000007)08.06.2012 11:13:29 - (not logged in) (::1)> USER user
(000007)08.06.2012 11:13:29 - (not logged in) (::1)> 331 Password required for user
(000007)08.06.2012 11:13:29 - (not logged in) (::1)> PASS ********
(000007)08.06.2012 11:13:29 - user (::1)> 230 Logged on
(000007)08.06.2012 11:13:29 - user (::1)> SYST
(000007)08.06.2012 11:13:29 - user (::1)> 215 UNIX emulated by FileZilla
(000007)08.06.2012 11:13:29 - user (::1)> FEAT
(000007)08.06.2012 11:13:29 - user (::1)> 211-Features:
(000007)08.06.2012 11:13:29 - user (::1)>  MDTM
(000007)08.06.2012 11:13:29 - user (::1)>  REST STREAM
(000007)08.06.2012 11:13:29 - user (::1)>  SIZE
(000007)08.06.2012 11:13:29 - user (::1)>  MLST type*;size*;modify*;
(000007)08.06.2012 11:13:29 - user (::1)>  MLSD
(000007)08.06.2012 11:13:29 - user (::1)>  UTF8
(000007)08.06.2012 11:13:29 - user (::1)>  CLNT
(000007)08.06.2012 11:13:29 - user (::1)>  MFMT
(000007)08.06.2012 11:13:29 - user (::1)> 211 End
(000007)08.06.2012 11:13:29 - user (::1)> PWD
(000007)08.06.2012 11:13:29 - user (::1)> 257 "/" is current directory.
(000007)08.06.2012 11:13:29 - user (::1)> TYPE I
(000007)08.06.2012 11:13:29 - user (::1)> 200 Type set to I
(000007)08.06.2012 11:13:29 - user (::1)> EPSV
(000007)08.06.2012 11:13:29 - user (::1)> 229 Entering Extended Passive Mode (|||49358|)
(000007)08.06.2012 11:13:29 - user (::1)> MLSD
(000007)08.06.2012 11:13:29 - user (::1)> 150 Connection accepted
(000007)08.06.2012 11:13:29 - user (::1)> 226 Transfer OK


the filezilla log :
Status:   Aufl
0 votes
by (162k points)
Are you using Java 7?

It could be this Java bug:

http://www.enterprisedt.com/forums/viewtopic.php?t=3893

Categories

...