This repository was archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (43 loc) · 1.36 KB
/
index.js
File metadata and controls
53 lines (43 loc) · 1.36 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
require("dotenv").config();
const FtpSrv = require('ftp-srv');
const path = require("path").join;
var color = require("cli-color").yellowBright;
const fs = require('fs');
const options = {
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem')
};
const port = 21;
const ftpServer = new FtpSrv({
url: "ftp://0.0.0.0:" + port,
anonymous: false,
tls: options
});
const config = require(path(__dirname, 'account.json'));
const username1 = config.username;
const password1 = config.password;
const dir = config.dir;
ftpServer.on('login', (data, resolve, reject) => {
if(data.username === username1 && data.password === password1){
return resolve({ root: dir });
}
return reject(new errors.GeneralError('Invalid username or password', 401));
});
ftpServer.listen().then(() => {
console.log(color.yellowBright('Ftp server is starting...'));
});
ftpServer.on('disconnect', ({id, newConnectionCount}) => {
console.log(color.bgMagenta('ID: ', id, 'Connection count: ', newConnectionCount));
});
ftpServer.on('client-error', ({context, error}) => {
console.log(color.bgRed(context, error));
});
ftpServer.on('server-error', ({error}) => {
console.log(color.red(error))
});
ftpServer.on('closing', ({}) => {
console.log('closing');
});
ftpServer.on('closed', ({}) => {
console.log('FTP server closed');
});