-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
60 lines (55 loc) · 1.98 KB
/
main.js
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
54
55
56
57
58
59
60
const {FtpServer} = require("./lib/ftpserver");
const {Parser} = require("ringo/args");
const term = require("ringo/term");
const parser = new Parser();
parser.addOption("p", "port", "port", "The port to listen (defaults to 2100)");
parser.addOption(null, "keystore", "keystore", "The path to the SSL keystore");
parser.addOption(null, "password", "password", "The SSL keystore passphrase");
parser.addOption(null, "protocol", "protocol", "The encryption protocol (ssl/tls)");
parser.addOption(null, "explicitSsl", null, "Use explicit SSL encryption");
const help = function() {
term.writeln("Usage:");
term.writeln("\n ringo main.js [options] path/to/users.json\n");
term.writeln("Available options:");
term.writeln(parser.help());
term.writeln();
};
const start = function(args) {
if (args.length < 1) {
return help();
}
const opts = {};
try {
parser.parse(args, opts);
} catch (e) {
term.writeln(term.RED, e.message, term.RESET);
return help();
}
const usersFile = args.pop();
if (!usersFile) {
term.writeln(term.RED,
"Please specify the JSON file containing the ftp accounts",
term.RESET);
return help();
}
let sslConfig = null;
if (opts.keystore) {
sslConfig = FtpServer.createSslConfig({
"keystore": opts.keystore,
"password": opts.password,
"protocol": opts.protocol || "tls"
});
}
const listener = FtpServer.createListener({
"port": opts.port || 2100,
"sslConfig": sslConfig,
"useImplicitSsl": opts.explicitSsl !== true
});
const userManager = FtpServer.createUserManager(usersFile);
userManager.on("reloaded", function(e) { print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> reloaded users <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")});
const server = new FtpServer(listener, userManager);
server.start();
};
if (require.main == module.id) {
start(require('system').args.slice(1));
}