在java中创建FTP客户端登录问题

在java中创建FTP客户端登录问题,java,apache,ftp,Java,Apache,Ftp,我正在使用commons.net api来创建到FTP服务器的连接。简单的代码 String Path = "D:\\FTP"; File ftpDirectory = new File(Path); ftpDirectory.mkdirs(); FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); factory.setPort(222

我正在使用commons.net api来创建到FTP服务器的连接。简单的代码

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
登录,如下所示

        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);
但我发现登录服务器时出现了问题。 我可以轻松启动服务器,但无法登录到服务器。。 我的输出看起来像

连接完成

过了很长一段时间,我得到了一个例外

org.apache.commons.net.ftp.FTPConnectionClosedException:连接 无指示关闭。在 org.apache.commons.net.ftp.ftp.\uu getReply(ftp.java:313)位于 org.apache.commons.net.ftp.ftp.\uu getReply(ftp.java:290)位于 org.apache.commons.net.ftp.ftp.sendCommand(ftp.java:474)位于 org.apache.commons.net.ftp.ftp.sendCommand(ftp.java:547)位于 org.apache.commons.net.ftp.ftp.user(ftp.java:693)位于 org.apache.commons.net.ftp.FTPClient.login(FTPClient.java:872)位于 TestFTPServer.connectServer(TestFTPServer.java:213)位于 main(TestFTPServer.java:52)


我无法从这里继续…

代码看起来很好(运行也很好),因此它可能是您的网络设置中的一部分。尝试将客户机和服务器中的“192.168.1.110”地址更改为“localhost”,看看是否有效。如果确实如此,那么您需要调查您的网络设置。

很抱歉打扰您,但我最终找到了一个解决方案。。 这是我愚蠢的错误..当我将jar升级到最新版本时,我使用的是commons.net-3.0版本,例如commons.net-3.3,错误完全消失了…因此,如果您遇到此错误,只需像那样升级jar


“祝您编码愉快”。

那么您会遇到什么错误?我已经编辑了我的问题,这是一个日志配置错误-请遵循给定的链接并应用其中一个建议的JAR(而不是-nop,因为您希望看到消息)。希望您会收到一条有用的错误消息。好吧,这个问题通过slf4j nop依赖项解决了,但没有更多日志,现在出现类似FTPConnectionClosedException的异常。我已将IP替换为本地主机,但没有发现任何效果