如何在Node.js中设置ftp-srv的根目录
How to set root directory of ftp-srv in Node.js
我正在尝试使用 ftp-srv
创建一个 ftp 服务器
这是我的代码:
const FtpSvr = require ( 'ftp-srv' );
const hostname = '0.0.0.0';
const port = 5053
const ftpServer = new FtpSvr ({
url:'ftp://' + hostname + ':' + port ,
anonymous: false,
greeting : [ "Hello user"]
});
ftpServer.on('login', (data, resolve, reject) => {
if(data.username === "user1" && data.password === "ip1") {
// call resolve
return resolve({root: '/home/test1/'});
}
else{
// if password and username are incorrectly then call reject
reject({});
}
});
ftpServer.listen()
.then(() =>
{
console.log ( `Server Running at ftp://${hostname}:${port}/` );
});
我已经将'/home/test1/'设置为根目录并且'test1'权限设置为777,但是在客户端,它引发了一个错误
an error occurred opening that folder on the ftp server make sure you have permission
我还尝试了另一个 ftp 客户端 (winscp),它引发了这个错误:
Could not retrieve directory listing. Command not supported
我真的很迷茫!
终于找到了ftp-srv的正确选项。它现在正在运行:
const FtpSvr = require ( 'ftp-srv' );
const hostname = '0.0.0.0';
const port = 5053
const ftpServer = new FtpSvr ({
url:'ftp://' + hostname + ':' + port ,
pasv_url:'ftp://172.18.56.71' ,
pasv_min:5054,
pasv_max:5055,
file_format: "ls",
anonymous: false,
greeting : [ "Hello user"]
});
ftpServer.on('login', (data, resolve, reject) => {
if(data.username === "user1" && data.password === "ip1") {
// call resolve
return resolve({root: './test/'});
}
else{
// if password and username are incorrectly then call reject
reject({});
}
});
ftpServer.listen()
.then(() =>
{
console.log ( `Server Running at ftp://${hostname}:${port}/` );
});
我正在尝试使用 ftp-srv
创建一个 ftp 服务器这是我的代码:
const FtpSvr = require ( 'ftp-srv' );
const hostname = '0.0.0.0';
const port = 5053
const ftpServer = new FtpSvr ({
url:'ftp://' + hostname + ':' + port ,
anonymous: false,
greeting : [ "Hello user"]
});
ftpServer.on('login', (data, resolve, reject) => {
if(data.username === "user1" && data.password === "ip1") {
// call resolve
return resolve({root: '/home/test1/'});
}
else{
// if password and username are incorrectly then call reject
reject({});
}
});
ftpServer.listen()
.then(() =>
{
console.log ( `Server Running at ftp://${hostname}:${port}/` );
});
我已经将'/home/test1/'设置为根目录并且'test1'权限设置为777,但是在客户端,它引发了一个错误
an error occurred opening that folder on the ftp server make sure you have permission
我还尝试了另一个 ftp 客户端 (winscp),它引发了这个错误:
Could not retrieve directory listing. Command not supported
我真的很迷茫!
终于找到了ftp-srv的正确选项。它现在正在运行:
const FtpSvr = require ( 'ftp-srv' );
const hostname = '0.0.0.0';
const port = 5053
const ftpServer = new FtpSvr ({
url:'ftp://' + hostname + ':' + port ,
pasv_url:'ftp://172.18.56.71' ,
pasv_min:5054,
pasv_max:5055,
file_format: "ls",
anonymous: false,
greeting : [ "Hello user"]
});
ftpServer.on('login', (data, resolve, reject) => {
if(data.username === "user1" && data.password === "ip1") {
// call resolve
return resolve({root: './test/'});
}
else{
// if password and username are incorrectly then call reject
reject({});
}
});
ftpServer.listen()
.then(() =>
{
console.log ( `Server Running at ftp://${hostname}:${port}/` );
});