[英]Apache Mina Java FTP Server Implementation - Client Stuck Waiting For Welcome Message
I am implementing an FTP server in Java for a project. 我正在用Java在项目中实现FTP服务器。 I can start the server but when I try to connect with a client it is stuck on "waiting for welcome message".
我可以启动服务器,但是当我尝试与客户端连接时,它停留在“等待欢迎消息”上。 I've looked at several examples but I'm not sure where I'm going wrong.
我看了几个例子,但是我不确定哪里出了问题。 Here is the class I have.
这是我上的课。 I will eventually break some of this out into other methods.
我最终将其中一些分解为其他方法。
The user parameters have been cleared for the purposes of this post. 出于这篇文章的目的,已经清除了用户参数。
public class FTPServer {
final int PORT = 2221;
String userfile = "";
String username="";
String password = ""
String homedir ="";
private FtpServer server=null;
public FTPServer() {}
public FTPServer(final String ipaddress, final int port){
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerfactory = new ListenerFactory();
listenerfactory.setDataConnectionConfiguration(
new DataConnectionConfigurationFactory().createDataConnectionConfiguration());
ConnectionConfigFactory connection = new ConnectionConfigFactory();
connection.setMaxLoginFailures(10);
connection.setLoginFailureDelay(5);
connection.setAnonymousLoginEnabled(false);
// set the ip address of the listener
listenerfactory.setServerAddress(ipaddress);
// set the port of the listener
if (port == 0)
{ listenerfactory.setPort(PORT);}
else {listenerfactory.setPort(port);
// replace the default listener
serverFactory.addListener("default", listenerfactory.createListener());
serverFactory.setConnectionConfig(connection.createConnectionConfig());
}
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
userManagerFactory.setFile(new File(userfile));
userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
UserManager um = userManagerFactory.createUserManager();
BaseUser user = new BaseUser();
user.setName(username);
user.setPassword(password);
user.setHomeDirectory(homedir);
try {
um.save(user);
} catch (FtpException e1) {
// TODO Auto-generated catch block
this.StopServer();
e1.printStackTrace();
}
serverFactory.setUserManager(um);
server = serverFactory.createServer();
}
public void StopServer(){ this.server.stop(); }
public void StartServer()
{
try {
server.start();
} catch (FtpException e) {
// handle this eventually, good enough for testing now
e.printStackTrace();
}
}
Here is the code that creates the server and starts and stops it 这是创建服务器并启动和停止服务器的代码
final int port = 0;
final String ipaddress = "";
FTPServer server = new FTPServer(ipaddress,port);
server.StartServer();
server.StopServer();
I'd say that FtpServer.Start
only starts listening on the incoming port. 我要说的是
FtpServer.Start
只开始侦听传入的端口。 It does not block. 它不会阻止。 You kill the server immediately afterwards by calling
.Stop
. 之后,您可以通过调用
.Stop
杀死服务器。
You have to wait in your code explicitly to keep the server running. 您必须显式等待代码以保持服务器运行。
server.StartServer();
Thread.sleep(Long.MAX_VALUE);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.