-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQFTPServer.java
More file actions
53 lines (44 loc) · 1.57 KB
/
Copy pathQFTPServer.java
File metadata and controls
53 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import QFTP.QFTPContext;
import QFTP.QFTPControlServer;
import QFTP.QFTPSession;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
public class QFTPServer {
private static String welcomeMessage = "200 Welcome to the server, please enter the file you would like to download.";
private static QFTPContext context;
public static void main(String[] args) {
if(args.length != 2) {
System.out.println("usage: java QFTPServer <control port> <directory root>");
return;
}
context = new QFTPContext();
context.positionCache = new HashMap<>();
context.welcomeMessage = welcomeMessage;
context.directoryRoot = args[1];
new Thread(new QFTPControlServer(context)).start();
ServerSocket serverSocket;
try {
context.controlPort = Integer.parseInt(args[0]);
serverSocket = new ServerSocket(context.controlPort);
} catch (IOException e) {
System.err.println("Problem connecting to port 17, please use sudo.");
return;
}
while(true) {
try {
Socket socket = serverSocket.accept();
new Thread(() -> {
try {
new QFTPSession(context, socket).run();
} catch (IOException e) {
e.printStackTrace();
}
}).start();
} catch(IOException e) {
e.printStackTrace();
}
}
}
}