我正在尝试使用“Apache FTP Server”创建一个具有内置/嵌入式FTP服务器的应用程序。我选择从MySQL数据库管理/验证用户。因此,我使用DbUserManager来处理用户创建,删除和列表。我能够管理除身份验证之外的所有用户相关操作。我无法从FTP客户端登录。服务器甚至不询问密码,只是给出消息“连接由远程主机关闭”。还有一个观察结果是 - 如果用户不在DB中,那么它要求输入密码,但最终会给出身份验证失败的消息。
这是代码,
public class Dumper {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
FtpServerFactory serverFactory;
FtpServer server;
ConnectionConfigFactory connectionConfigFactory;
ConnectionConfig connectionConfig;
DbUserManagerFactory userManagerFactory;
DbUserManager userManager;
BasicDataSource bdSource;
final Map<String, Ftplet> ftpletMap;
Ftplet ftplet;
// TODO code application logic here
System.out.println("I am Dumper!!");
connectionConfigFactory = new ConnectionConfigFactory();
connectionConfigFactory.setAnonymousLoginEnabled(true);
connectionConfig = connectionConfigFactory.createConnectionConfig();
ftpletMap = new HashMap<>();
ftplet = new DumperLet();
ftpletMap.put("default", ftplet);
// Data Source
bdSource = new BasicDataSource();
bdSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
bdSource.setUrl("jdbc:mysql://localhost:3306/apsdma");
bdSource.setUsername("apsdma");
bdSource.setPassword("apsdma");
// Database User Manager
userManagerFactory = new DbUserManagerFactory();
userManagerFactory.setPasswordEncryptor(new Md5PasswordEncryptor());
userManagerFactory.setAdminName("ambedkar");
userManagerFactory.setDataSource(bdSource);
userManagerFactory.setSqlUserInsert("INSERT INTO FTP_USER (userid, userpassword, homedirectory, enableflag, writepermission, idletime,uploadrate, downloadrate) VALUES ('{userid}', '{userpassword}', '{homedirectory}', {enableflag}, {writepermission}, {idletime}, {uploadrate}, {downloadrate})");
userManagerFactory.setSqlUserUpdate("UPDATE FTP_USER SET userpassword='{userpassword}', homedirectory='{homedirectory}', enableflag={enableflag}, writepermission={writepermission}, idletime={idletime}, uploadrate={uploadrate}, downloadrate={downloadrate} WHERE userid='{userid}'");
userManagerFactory.setSqlUserDelete("DELETE FROM FTP_USER WHERE userid = '{userid}'");
userManagerFactory.setSqlUserSelect("SELECT userid, userpassword, homedirectory, enableflag, writepermission, idletime, uploadrate, downloadrate FROM FTP_USER WHERE userid = '{userid}'");
userManagerFactory.setSqlUserSelectAll("SELECT userid FROM FTP_USER ORDER BY userid");
userManagerFactory.setSqlUserAdmin("SELECT userid FROM FTP_USER WHERE userid='{userid}' AND userid='ambedkar'");
userManagerFactory.setSqlUserAuthenticate("SELECT userpassword from FTP_USER WHERE userid='{userid}'");
userManager = (DbUserManager) userManagerFactory.createUserManager();
serverFactory = new FtpServerFactory();
serverFactory.setConnectionConfig(connectionConfig);
serverFactory.setFtplets(ftpletMap);
serverFactory.setUserManager(userManager);
server = serverFactory.createServer();
try {
server.start();
} catch (FtpException ex) {
Logger.getLogger(Dumper.class.getName()).log(Level.SEVERE, null, ex);
System.out.println(ex.getMessage());
}
}
}
这是客户端输出的屏幕截图,
有人可以指导我出了什么问题或在哪里寻找解决方案,请...
是“enableflag”字段在数据库中设置为FALSE还是1?如果使用提供的sql文件创建表,则默认情况下此字段设置为TRUE。
问候