UNPKG

node-red-webpty

Version:

* web-pty: run node-pty on node-red host * ftp-srv: run a ftp-srv on node-red host

43 lines (37 loc) 1.27 kB
const { FtpSrv, ftpErrors } = require('ftp-srv'); module.exports = function(RED){ console.log('red ftp is loaded...'); function FTPServer(config){ RED.nodes.createNode(this, config); if(RED.__ftp_srv) { return; } const ftpServer = new FtpSrv({ url: config.url, anonymous: config.anonymous, pasv_min: +config.pasvMin, pasv_max: +config.pasvMax, }); console.log('ref ftp is listen on ', config.url, config.username, config.password) RED.__ftp_srv = ftpServer; ftpServer.on('login', ({ connection, username, password }, resolve, reject) => { if(!config.anonymous){ if(config.username && config.password && username === config.username && password === config.password){ return resolve({ root:"/" }); } return reject(new ftpErrors.GeneralError('Invalid username or password', 401)); } return resolve({ root: '/' }) }); ftpServer.listen().then(() => { console.log('Ftp server is starting...') }); this.on('close', (done) => { console.log('ftp server close') ftpServer.close() delete RED.__ftp_srv; done() }) } RED.nodes.registerType('ftp-srv', FTPServer); }