MCSManager/ftpd/index.js
2017-11-13 12:26:31 +08:00

65 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const ftpServerInterface = require('./ftpserver');
const userModel = require('../model/UserModel');
const permission = require('../helper/Permission');
const serverModel = require('../model/ServerModel');
ftpServerInterface.createFTPServer({
getInitialCwd: function () {
return '/';
},
getRoot: function (connected) {
let username = connected.username;
let arrName = username.split('.');
if (arrName.length != 2) return false;
let realName = arrName[0];
let serverName = arrName[1];
if (!realName || !serverName) return false;
let user = userModel.userCenter().get(realName);
//if (serverModel.ServerManager().isExist(serverName) && permission.isCanServer(realName, serverName)) {
let dataModel = serverModel.ServerManager().getServer(serverName).dataModel || null;
if (dataModel) return dataModel.cwd;
//}
// connected.close();
//return null;
// return process.cwd() + '/' + connected.username;
},
pasvPortRangeStart: 1025,
pasvPortRangeEnd: 1050,
tlsOptions: null,
allowUnauthorizedTls: false,
useWriteFile: false, //true 则客户端上传的文件将缓冲在内存中然后使用写入磁盘writeFile。
useReadFile: false,
maxStatsAtOnce: 10,
// uploadMaxSlurpSize: uploadMaxSlurpSize // N/A unless 'useWriteFile' is true.
});
ftpServerInterface.initFTPServerListener({
loginCheck: (connection, username, password) => {
let usname = username || '';
let arrName = usname.split('.');
let serverName = arrName[1];
let userName = arrName[0];
if (serverModel.ServerManager().isExist(serverName) && permission.isCanServer(userName, serverName)) {
try {
return userModel.loginUser(userName, password);
} catch (e) {
return false;
}
}
return false;
},
error: () => {
return false;
}
});
//run
ftpServerInterface.runFTPServer();