Java – Creating FTP Client Login Issue In java

apacheftpjava

I am using commons.net api in order to create connection to the FTP server. simple code like

String Path = "D:\\FTP";
File ftpDirectory = new File(Path);
ftpDirectory.mkdirs();

FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory factory = new ListenerFactory();
factory.setPort(2221); 
factory.setServerAddress("192.168.1.110");

serverFactory.addListener("default", factory.createListener());
PropertiesUserManagerFactory userFactory = new PropertiesUserManagerFactory();
File userFile = new File("D:\\FTP\\users.properties");
userFactory.setFile(userFile);

//UserManager um = userFactory.createUserManager();
UserManager um =new PropertiesUserManager(new ClearTextPasswordEncryptor(),userFile,"admin");
BaseUser user = new BaseUser();
user.setName("test");
user.setPassword("test");
user.setHomeDirectory(Path);
um.save(user);

serverFactory.setUserManager(um);

FtpServer ftpServer = serverFactory.createServer();
ftpServer.start();

FTPClient Login as shown below

        FTPClient ftp = new FTPClient();
        ftp.connect("192.168.1.110",2221);
        System.out.println("connect done");
        String loging_success = ftp.login("test", "test") == true ? "success" : "failed"; 
        System.out.println("login: "+ loging_success);

but i found trouble in order to login to the server.
i can start server easily but couldn't login to the server..
my output look like

connect done

after long time get exception like

org.apache.commons.net.ftp.FTPConnectionClosedException: Connection
closed without indication. at
org.apache.commons.net.ftp.FTP.__getReply(FTP.java:313) 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.FTP.user(FTP.java:693) at
org.apache.commons.net.ftp.FTPClient.login(FTPClient.java:872) at
TestFTPServer.connectServer(TestFTPServer.java:213) at
TestFTPServer.main(TestFTPServer.java:52)

I can't move forward from here…

Best Answer

sorry for bothering you but finally i founded a solution.. it was my silly mistake..i was using commons.net-3.0 version when i upgraded that jar to latest version e.g. commons.net-3.3 the error was gone totally...so if you are getting this error just upgrade your jars just like that..

"have fun codding"..