0

i am running a ftp server with ftp-srv and i need to limit the space for each user , the ftp-srv package don't have a feature to do this, however i find a answer to same issue on github , but its so general and confusing , i was hopping that someone can walk me through how can i implement this solution or another solution

ftp-srv repo url => https://github.com/QuorumDMS/ftp-srv

github ansewer to the issue => https://github.com/QuorumDMS/ftp-srv/issues/196

my current script to run the ftp server:

const { FtpSrv } = require("ftp-srv");
const { networkInterfaces } = require("os");
const { Netmask } = require("netmask");

const nets = networkInterfaces();
function getNetworks() {
  let networks = {};
  for (const name of Object.keys(nets)) {
    for (const net of nets[name]) {
      if (net.family === "IPv4" && !net.internal) {
        networks[net.address + "/24"] = net.address;
      }
    }
  }
  return networks;
}

const resolverFunction = (address) => {
  // const networks = {
  //     '$GATEWAY_IP/32': `${public_ip}`,
  //     '10.0.0.0/8'    : `${lan_ip}`
  // }
  const networks = getNetworks();
  for (const network in networks) {
    if (new Netmask(network).contains(address)) {
      return networks[network];
    }
  }
  return "127.0.0.1";
};


const port = 2141;
const ftpServer = new FtpSrv({
  url: "ftp://0.0.0.0:" + port,
  anonymous: false,
  pasv_url: resolverFunction,
  pasv_min: 60000,
  pasv_max: 61000,
  file_format: "ls",
});

// List of valid FTP user credentials
const users = [
  {
    username: "user1",
    password: "password1",
    root: "/Servers/1245",
    maxSize: 1024,
  },
  // add more users as needed
];



ftpServer.on("login", ({ connection, username, password }, resolve, reject) => {
  const user = users.find(
    (u) => u.username === username && u.password === password
  );
  if (user) {
    resolve({ root: user.root });
  } else {
    reject(new Error("Invalid username or password"));
  }
});

ftpServer.listen().then(() => {
  console.log("FTP server listening on port 2141");
});

4lireza
  • 3
  • 2

0 Answers0