feat: convert commonjs to esm modules
This commit is contained in:
12
ftp-srv.js
12
ftp-srv.js
@@ -1,8 +1,6 @@
|
|||||||
const FtpSrv = require('./src')
|
import FtpSrv from './src/index.js'
|
||||||
const FileSystem = require('./src/fs')
|
import FileSystem from './src/fs.js'
|
||||||
const errors = require('./src/errors')
|
import ftpErrors from './src/errors.js'
|
||||||
|
|
||||||
module.exports = FtpSrv
|
export default FtpSrv
|
||||||
module.exports.FtpSrv = FtpSrv
|
export { FtpSrv, FileSystem, ftpErrors }
|
||||||
module.exports.FileSystem = FileSystem
|
|
||||||
module.exports.ftpErrors = errors
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"bin",
|
"bin",
|
||||||
"ftp-srv.d.ts"
|
"ftp-srv.d.ts"
|
||||||
],
|
],
|
||||||
|
"type": "module",
|
||||||
"main": "ftp-srv.js",
|
"main": "ftp-srv.js",
|
||||||
"bin": "./bin/index.js",
|
"bin": "./bin/index.js",
|
||||||
"types": "./ftp-srv.d.ts",
|
"types": "./ftp-srv.d.ts",
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
import REGISTRY from './registry.js'
|
||||||
const REGISTRY = require('./registry')
|
|
||||||
|
|
||||||
const CMD_FLAG_REGEX = new RegExp(/^-(\w{1})$/)
|
const CMD_FLAG_REGEX = new RegExp(/^-(\w{1})$/)
|
||||||
|
|
||||||
class FtpCommands {
|
export default class FtpCommands {
|
||||||
constructor(connection) {
|
constructor(connection) {
|
||||||
this.connection = connection
|
this.connection = connection
|
||||||
this.previousCommand = {}
|
this.previousCommand = {}
|
||||||
@@ -75,4 +74,3 @@ class FtpCommands {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = FtpCommands
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'ABOR',
|
directive: 'ABOR',
|
||||||
handler: function () {
|
handler: function () {
|
||||||
return this.connector
|
return this.connector
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'ALLO',
|
directive: 'ALLO',
|
||||||
handler: function () {
|
handler: function () {
|
||||||
return this.reply(202)
|
return this.reply(202)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const stor = require('./stor').handler
|
import stor from './stor.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'APPE',
|
directive: 'APPE',
|
||||||
handler: function (args) {
|
handler: function (args) {
|
||||||
return stor.call(this, args)
|
return stor.handler.call(this, args)
|
||||||
},
|
},
|
||||||
syntax: '{{cmd}} <path>',
|
syntax: '{{cmd}} <path>',
|
||||||
description: 'Append to a file'
|
description: 'Append to a file'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const tls = require('tls')
|
import tls from 'node:tls'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'AUTH',
|
directive: 'AUTH',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
const method = _.upperCase(command.arg)
|
const method = _.upperCase(command.arg)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const cwd = require('./cwd').handler
|
import cwd from './cwd.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: ['CDUP', 'XCUP'],
|
directive: ['CDUP', 'XCUP'],
|
||||||
handler: function (args) {
|
handler: function (args) {
|
||||||
args.command.arg = '..'
|
args.command.arg = '..'
|
||||||
return cwd.call(this, args)
|
return cwd.handler.call(this, args)
|
||||||
},
|
},
|
||||||
syntax: '{{cmd}}',
|
syntax: '{{cmd}}',
|
||||||
description: 'Change to Parent Directory'
|
description: 'Change to Parent Directory'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const escapePath = require('../../helpers/escape-path')
|
import escapePath from '../../helpers/escape-path.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: ['CWD', 'XCWD'],
|
directive: ['CWD', 'XCWD'],
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'DELE',
|
directive: 'DELE',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const ActiveConnector = require('../../connector/active')
|
import ActiveConnector from '../../connector/active.js'
|
||||||
|
|
||||||
const FAMILY = {
|
const FAMILY = {
|
||||||
1: 4,
|
1: 4,
|
||||||
2: 6
|
2: 6
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'EPRT',
|
directive: 'EPRT',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
const [, protocol, ip, port] = _.chain(command).get('arg', '').split('|').value()
|
const [, protocol, ip, port] = _.chain(command).get('arg', '').split('|').value()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const PassiveConnector = require('../../connector/passive')
|
import PassiveConnector from '../../connector/passive.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'EPSV',
|
directive: 'EPSV',
|
||||||
handler: function ({ log }) {
|
handler: function ({ log }) {
|
||||||
this.connector = new PassiveConnector(this)
|
this.connector = new PassiveConnector(this)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'FEAT',
|
directive: 'FEAT',
|
||||||
handler: function () {
|
handler: function () {
|
||||||
const registry = require('../registry')
|
const registry = import('../registry')
|
||||||
const features = Object.keys(registry)
|
const features = Object.keys(registry)
|
||||||
.reduce(
|
.reduce(
|
||||||
(feats, cmd) => {
|
(feats, cmd) => {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'HELP',
|
directive: 'HELP',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
const registry = require('../registry')
|
const registry = import('../registry')
|
||||||
const directive = _.upperCase(command.arg)
|
const directive = _.upperCase(command.arg)
|
||||||
if (directive) {
|
if (directive) {
|
||||||
if (!registry.hasOwnProperty(directive)) return this.reply(502, `Unknown command ${directive}.`)
|
if (!registry.hasOwnProperty(directive)) return this.reply(502, `Unknown command ${directive}.`)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const getFileStat = require('../../helpers/file-stat')
|
import getFileStat from '../../helpers/file-stat.js'
|
||||||
|
|
||||||
// http://cr.yp.to/ftp/list.html
|
// http://cr.yp.to/ftp/list.html
|
||||||
// http://cr.yp.to/ftp/list/eplf.html
|
// http://cr.yp.to/ftp/list/eplf.html
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'LIST',
|
directive: 'LIST',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const moment = require('moment')
|
import moment from 'moment'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'MDTM',
|
directive: 'MDTM',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const escapePath = require('../../helpers/escape-path')
|
import escapePath from '../../helpers/escape-path.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: ['MKD', 'XMKD'],
|
directive: ['MKD', 'XMKD'],
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'MODE',
|
directive: 'MODE',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
return this.reply(/^S$/i.test(command.arg) ? 200 : 504)
|
return this.reply(/^S$/i.test(command.arg) ? 200 : 504)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const list = require('./list').handler
|
import list from './list.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'NLST',
|
directive: 'NLST',
|
||||||
handler: function (args) {
|
handler: function (args) {
|
||||||
return list.call(this, args)
|
return list.handler.call(this, args)
|
||||||
},
|
},
|
||||||
syntax: '{{cmd}} [<path>]',
|
syntax: '{{cmd}} [<path>]',
|
||||||
description: 'Returns a list of file names in a specified directory'
|
description: 'Returns a list of file names in a specified directory'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'NOOP',
|
directive: 'NOOP',
|
||||||
handler: function () {
|
handler: function () {
|
||||||
return this.reply(200)
|
return this.reply(200)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
|
|
||||||
const OPTIONS = {
|
const OPTIONS = {
|
||||||
UTF8: utf8,
|
UTF8: utf8,
|
||||||
'UTF-8': utf8
|
'UTF-8': utf8
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'OPTS',
|
directive: 'OPTS',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
if (!_.has(command, 'arg')) return this.reply(501)
|
if (!_.has(command, 'arg')) return this.reply(501)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'PASS',
|
directive: 'PASS',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.username) return this.reply(503)
|
if (!this.username) return this.reply(503)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const PassiveConnector = require('../../connector/passive')
|
import PassiveConnector from '../../connector/passive.js'
|
||||||
const { isLocalIP } = require('../../helpers/is-local')
|
import { isLocalIP } from '../../helpers/is-local.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'PASV',
|
directive: 'PASV',
|
||||||
handler: function ({ log } = {}) {
|
handler: function ({ log } = {}) {
|
||||||
if (!this.server.options.pasv_url) {
|
if (!this.server.options.pasv_url) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'PBSZ',
|
directive: 'PBSZ',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
if (!this.secure) return this.reply(202, 'Not supported')
|
if (!this.secure) return this.reply(202, 'Not supported')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const ActiveConnector = require('../../connector/active')
|
import ActiveConnector from '../../connector/active.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'PORT',
|
directive: 'PORT',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
this.connector = new ActiveConnector(this)
|
this.connector = new ActiveConnector(this)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'PROT',
|
directive: 'PROT',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
if (!this.secure) return this.reply(202, 'Not supported')
|
if (!this.secure) return this.reply(202, 'Not supported')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const escapePath = require('../../helpers/escape-path')
|
import escapePath from '../../helpers/escape-path.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: ['PWD', 'XPWD'],
|
directive: ['PWD', 'XPWD'],
|
||||||
handler: function ({ log } = {}) {
|
handler: function ({ log } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'QUIT',
|
directive: 'QUIT',
|
||||||
handler: function () {
|
handler: function () {
|
||||||
return this.close(221, 'Client called QUIT')
|
return this.close(221, 'Client called QUIT')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'REST',
|
directive: 'REST',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
const arg = _.get(command, 'arg')
|
const arg = _.get(command, 'arg')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'RETR',
|
directive: 'RETR',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const { handler: dele } = require('./dele')
|
import dele from './dele.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: ['RMD', 'XRMD'],
|
directive: ['RMD', 'XRMD'],
|
||||||
handler: function (args) {
|
handler: function (args) {
|
||||||
return dele.call(this, args)
|
return dele.handler.call(this, args)
|
||||||
},
|
},
|
||||||
syntax: '{{cmd}} <path>',
|
syntax: '{{cmd}} <path>',
|
||||||
description: 'Remove a directory'
|
description: 'Remove a directory'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'RNFR',
|
directive: 'RNFR',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'RNTO',
|
directive: 'RNTO',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.renameFrom) return this.reply(503)
|
if (!this.renameFrom) return this.reply(503)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
module.exports = function ({ log, command } = {}) {
|
export default function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
if (!this.fs.chmod) return this.reply(402, 'Not supported by file system')
|
if (!this.fs.chmod) return this.reply(402, 'Not supported by file system')
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
|
|
||||||
const registry = require('./registry')
|
import registry from './registry.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'SITE',
|
directive: 'SITE',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
const rawSubCommand = _.get(command, 'arg', '')
|
const rawSubCommand = _.get(command, 'arg', '')
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
module.exports = {
|
import chmod from './chmod.js'
|
||||||
|
export default {
|
||||||
CHMOD: {
|
CHMOD: {
|
||||||
handler: require('./chmod')
|
handler: chmod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'SIZE',
|
directive: 'SIZE',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const getFileStat = require('../../helpers/file-stat')
|
import getFileStat from '../../helpers/file-stat.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'STAT',
|
directive: 'STAT',
|
||||||
handler: function (args = {}) {
|
handler: function (args = {}) {
|
||||||
const { log, command } = args
|
const { log, command } = args
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'STOR',
|
directive: 'STOR',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const { handler: stor } = require('./stor')
|
import stor from './stor.js'
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
directive: 'STOU',
|
directive: 'STOU',
|
||||||
handler: function (args) {
|
handler: function (args) {
|
||||||
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
if (!this.fs) return this.reply(550, 'File system not instantiated')
|
||||||
@@ -13,7 +13,7 @@ module.exports = {
|
|||||||
.catch(() => fileName)
|
.catch(() => fileName)
|
||||||
.then((name) => {
|
.then((name) => {
|
||||||
args.command.arg = name
|
args.command.arg = name
|
||||||
return stor.call(this, args)
|
return stor.handler.call(this, args)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
syntax: '{{cmd}}',
|
syntax: '{{cmd}}',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'STRU',
|
directive: 'STRU',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
return this.reply(/^F$/i.test(command.arg) ? 200 : 504)
|
return this.reply(/^F$/i.test(command.arg) ? 200 : 504)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'SYST',
|
directive: 'SYST',
|
||||||
handler: function () {
|
handler: function () {
|
||||||
return this.reply(215)
|
return this.reply(215)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'TYPE',
|
directive: 'TYPE',
|
||||||
handler: function ({ command } = {}) {
|
handler: function ({ command } = {}) {
|
||||||
if (/^A[0-9]?$/i.test(command.arg)) {
|
if (/^A[0-9]?$/i.test(command.arg)) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
directive: 'USER',
|
directive: 'USER',
|
||||||
handler: function ({ log, command } = {}) {
|
handler: function ({ log, command } = {}) {
|
||||||
if (this.username) return this.reply(530, 'Username already set')
|
if (this.username) return this.reply(530, 'Username already set')
|
||||||
|
|||||||
@@ -1,44 +1,84 @@
|
|||||||
|
import abor from './registration/abor.js'
|
||||||
|
import allo from './registration/allo.js'
|
||||||
|
import appe from './registration/appe.js'
|
||||||
|
import auth from './registration/auth.js'
|
||||||
|
import cdup from './registration/cdup.js'
|
||||||
|
import cwd from './registration/cwd.js'
|
||||||
|
import dele from './registration/dele.js'
|
||||||
|
import feat from './registration/feat.js'
|
||||||
|
import help from './registration/help.js'
|
||||||
|
import list from './registration/list.js'
|
||||||
|
import mdtm from './registration/mdtm.js'
|
||||||
|
import mkd from './registration/mkd.js'
|
||||||
|
import mode from './registration/mode.js'
|
||||||
|
import nlst from './registration/nlst.js'
|
||||||
|
import noop from './registration/noop.js'
|
||||||
|
import opts from './registration/opts.js'
|
||||||
|
import pass from './registration/pass.js'
|
||||||
|
import pasv from './registration/pasv.js'
|
||||||
|
import port from './registration/port.js'
|
||||||
|
import pwd from './registration/pwd.js'
|
||||||
|
import quit from './registration/quit.js'
|
||||||
|
import rest from './registration/rest.js'
|
||||||
|
import retr from './registration/retr.js'
|
||||||
|
import rmd from './registration/rmd.js'
|
||||||
|
import rnfr from './registration/rnfr.js'
|
||||||
|
import rnto from './registration/rnto.js'
|
||||||
|
import site from './registration/site/index.js'
|
||||||
|
import size from './registration/size.js'
|
||||||
|
import stat from './registration/stat.js'
|
||||||
|
import stor from './registration/stor.js'
|
||||||
|
import stou from './registration/stou.js'
|
||||||
|
import stru from './registration/stru.js'
|
||||||
|
import syst from './registration/syst.js'
|
||||||
|
import type from './registration/type.js'
|
||||||
|
import user from './registration/user.js'
|
||||||
|
import pbsz from './registration/pbsz.js'
|
||||||
|
import prot from './registration/prot.js'
|
||||||
|
import eprt from './registration/eprt.js'
|
||||||
|
import epsv from './registration/epsv.js'
|
||||||
|
|
||||||
/* eslint no-return-assign: 0 */
|
/* eslint no-return-assign: 0 */
|
||||||
const commands = [
|
const commands = [
|
||||||
require('./registration/abor'),
|
abor,
|
||||||
require('./registration/allo'),
|
allo,
|
||||||
require('./registration/appe'),
|
appe,
|
||||||
require('./registration/auth'),
|
auth,
|
||||||
require('./registration/cdup'),
|
cdup,
|
||||||
require('./registration/cwd'),
|
cwd,
|
||||||
require('./registration/dele'),
|
dele,
|
||||||
require('./registration/feat'),
|
feat,
|
||||||
require('./registration/help'),
|
help,
|
||||||
require('./registration/list'),
|
list,
|
||||||
require('./registration/mdtm'),
|
mdtm,
|
||||||
require('./registration/mkd'),
|
mkd,
|
||||||
require('./registration/mode'),
|
mode,
|
||||||
require('./registration/nlst'),
|
nlst,
|
||||||
require('./registration/noop'),
|
noop,
|
||||||
require('./registration/opts'),
|
opts,
|
||||||
require('./registration/pass'),
|
pass,
|
||||||
require('./registration/pasv'),
|
pasv,
|
||||||
require('./registration/port'),
|
port,
|
||||||
require('./registration/pwd'),
|
pwd,
|
||||||
require('./registration/quit'),
|
quit,
|
||||||
require('./registration/rest'),
|
rest,
|
||||||
require('./registration/retr'),
|
retr,
|
||||||
require('./registration/rmd'),
|
rmd,
|
||||||
require('./registration/rnfr'),
|
rnfr,
|
||||||
require('./registration/rnto'),
|
rnto,
|
||||||
require('./registration/site'),
|
site,
|
||||||
require('./registration/size'),
|
size,
|
||||||
require('./registration/stat'),
|
stat,
|
||||||
require('./registration/stor'),
|
stor,
|
||||||
require('./registration/stou'),
|
stou,
|
||||||
require('./registration/stru'),
|
stru,
|
||||||
require('./registration/syst'),
|
syst,
|
||||||
require('./registration/type'),
|
type,
|
||||||
require('./registration/user'),
|
user,
|
||||||
require('./registration/pbsz'),
|
pbsz,
|
||||||
require('./registration/prot'),
|
prot,
|
||||||
require('./registration/eprt'),
|
eprt,
|
||||||
require('./registration/epsv')
|
epsv
|
||||||
]
|
]
|
||||||
|
|
||||||
const registry = commands.reduce((result, cmd) => {
|
const registry = commands.reduce((result, cmd) => {
|
||||||
@@ -47,4 +87,4 @@ const registry = commands.reduce((result, cmd) => {
|
|||||||
return result
|
return result
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
module.exports = registry
|
export default registry
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const uuid = require('uuid')
|
import uuid from 'uuid'
|
||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const EventEmitter = require('events')
|
import { EventEmitter } from 'node:events'
|
||||||
|
import BaseConnector from './connector/base.js'
|
||||||
|
import { FileSystem } from './fs.js'
|
||||||
|
import Commands from './commands/index.js'
|
||||||
|
import errors from './errors.js'
|
||||||
|
import DEFAULT_MESSAGE from './messages.js'
|
||||||
|
|
||||||
const BaseConnector = require('./connector/base')
|
export default class FtpConnection extends EventEmitter {
|
||||||
const FileSystem = require('./fs')
|
|
||||||
const Commands = require('./commands')
|
|
||||||
const errors = require('./errors')
|
|
||||||
const DEFAULT_MESSAGE = require('./messages')
|
|
||||||
|
|
||||||
class FtpConnection extends EventEmitter {
|
|
||||||
constructor(server, options) {
|
constructor(server, options) {
|
||||||
super()
|
super()
|
||||||
this.server = server
|
this.server = server
|
||||||
@@ -161,4 +160,3 @@ class FtpConnection extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = FtpConnection
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const { Socket } = require('net')
|
import { Socket } from 'node:net'
|
||||||
const tls = require('tls')
|
import tls from 'node:tls'
|
||||||
const ip = require('ip')
|
import ip from 'ip'
|
||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const Connector = require('./base')
|
import Connector from './base.js'
|
||||||
const { SocketError } = require('../errors')
|
import errors from '../errors.js'
|
||||||
|
|
||||||
class Active extends Connector {
|
export default class Active extends Connector {
|
||||||
constructor(connection) {
|
constructor(connection) {
|
||||||
super(connection)
|
super(connection)
|
||||||
this.type = 'active'
|
this.type = 'active'
|
||||||
@@ -29,7 +29,7 @@ class Active extends Connector {
|
|||||||
|
|
||||||
return closeExistingServer().then(() => {
|
return closeExistingServer().then(() => {
|
||||||
if (!ip.isEqual(this.connection.commandSocket.remoteAddress, host)) {
|
if (!ip.isEqual(this.connection.commandSocket.remoteAddress, host)) {
|
||||||
throw new SocketError('The given address is not yours', 500)
|
throw new errors.SocketError('The given address is not yours', 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataSocket = new Socket()
|
this.dataSocket = new Socket()
|
||||||
@@ -55,4 +55,3 @@ class Active extends Connector {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = Active
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const errors = require('../errors')
|
import errors from '../errors.js'
|
||||||
|
|
||||||
class Connector {
|
export default class Connector {
|
||||||
constructor(connection) {
|
constructor(connection) {
|
||||||
this.connection = connection
|
this.connection = connection
|
||||||
|
|
||||||
@@ -49,4 +49,3 @@ class Connector {
|
|||||||
this.connection.connector = new Connector(this)
|
this.connection.connector = new Connector(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = Connector
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
const net = require('net')
|
import net from 'node:net'
|
||||||
const tls = require('tls')
|
import tls from 'node:tls'
|
||||||
const ip = require('ip')
|
import ip from 'ip'
|
||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
const Connector = require('./base')
|
import Connector from './base.js'
|
||||||
const errors = require('../errors')
|
import errors from '../errors.js'
|
||||||
|
|
||||||
const CONNECT_TIMEOUT = 30 * 1000
|
const CONNECT_TIMEOUT = 30 * 1000
|
||||||
|
|
||||||
class Passive extends Connector {
|
export default class Passive extends Connector {
|
||||||
constructor(connection) {
|
constructor(connection) {
|
||||||
super(connection)
|
super(connection)
|
||||||
this.type = 'passive'
|
this.type = 'passive'
|
||||||
@@ -119,4 +119,3 @@ class Passive extends Connector {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = Passive
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class ConnectorError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
SocketError,
|
SocketError,
|
||||||
FileSystemError,
|
FileSystemError,
|
||||||
ConnectorError,
|
ConnectorError,
|
||||||
|
|||||||
19
src/fs.js
19
src/fs.js
@@ -1,15 +1,15 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const nodePath = require('path')
|
import nodePath from 'node:path'
|
||||||
const uuid = require('uuid')
|
import uuid from 'uuid'
|
||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const { createReadStream, createWriteStream, constants } = require('fs')
|
import { createReadStream, createWriteStream, constants } from 'node:fs'
|
||||||
const fsAsync = require('./helpers/fs-async')
|
import fsAsync from './helpers/fs-async.js'
|
||||||
const errors = require('./errors')
|
import errors from './errors.js'
|
||||||
|
|
||||||
const UNIX_SEP_REGEX = /\//g
|
const UNIX_SEP_REGEX = /\//g
|
||||||
const WIN_SEP_REGEX = /\\/g
|
const WIN_SEP_REGEX = /\\/g
|
||||||
|
|
||||||
class FileSystem {
|
export default class FileSystem {
|
||||||
constructor(connection, { root, cwd } = {}) {
|
constructor(connection, { root, cwd } = {}) {
|
||||||
this.connection = connection
|
this.connection = connection
|
||||||
this.cwd = nodePath.normalize((cwd || '/').replace(WIN_SEP_REGEX, '/'))
|
this.cwd = nodePath.normalize((cwd || '/').replace(WIN_SEP_REGEX, '/'))
|
||||||
@@ -141,4 +141,5 @@ class FileSystem {
|
|||||||
return uuid.v4().replace(/\W/g, '')
|
return uuid.v4().replace(/\W/g, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = FileSystem
|
|
||||||
|
export { FileSystem }
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module.exports = function (path) {
|
export default function (path) {
|
||||||
return path.replace(/"/g, '""')
|
return path.replace(/"/g, '""')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const moment = require('moment')
|
import moment from 'moment'
|
||||||
const errors = require('../errors')
|
import errors from '../errors.js'
|
||||||
|
|
||||||
const FORMATS = {
|
const FORMATS = {
|
||||||
ls,
|
ls,
|
||||||
ep
|
ep
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function (fileStat, format = 'ls') {
|
export default function (fileStat, format = 'ls') {
|
||||||
if (typeof format === 'function') return format(fileStat)
|
if (typeof format === 'function') return format(fileStat)
|
||||||
if (!FORMATS.hasOwnProperty(format)) {
|
if (!FORMATS.hasOwnProperty(format)) {
|
||||||
throw new errors.FileSystemError('Bad file stat formatter')
|
throw new errors.FileSystemError('Bad file stat formatter')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const net = require('net')
|
import net from 'node:net'
|
||||||
const errors = require('../errors')
|
import errors from '../errors.js'
|
||||||
|
|
||||||
const MAX_PORT = 65535
|
const MAX_PORT = 65535
|
||||||
const MAX_PORT_CHECK_ATTEMPT = 5
|
const MAX_PORT_CHECK_ATTEMPT = 5
|
||||||
@@ -56,7 +56,4 @@ function getNextPortFactory(host, portMin, portMax, maxAttempts = MAX_PORT_CHECK
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export { getNextPortFactory, portNumberGenerator }
|
||||||
getNextPortFactory,
|
|
||||||
portNumberGenerator
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const fs = require('fs')
|
import fs from 'node:fs'
|
||||||
const { promisify } = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
|
|
||||||
const methods = ['stat', 'readdir', 'access', 'unlink', 'rmdir', 'mkdir', 'rename', 'chmod']
|
const methods = ['stat', 'readdir', 'access', 'unlink', 'rmdir', 'mkdir', 'rename', 'chmod']
|
||||||
|
|
||||||
module.exports = methods.reduce((obj, method) => {
|
export default methods.reduce((obj, method) => {
|
||||||
obj[method] = promisify(fs[method])
|
obj[method] = Promise.promisify(fs[method])
|
||||||
return obj
|
return obj
|
||||||
}, {})
|
}, {})
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module.exports.isLocalIP = function (ip) {
|
export const isLocalIP = function (ip) {
|
||||||
return ip === '127.0.0.1' || ip == '::1'
|
return ip === '127.0.0.1' || ip == '::1'
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/index.js
22
src/index.js
@@ -1,15 +1,14 @@
|
|||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const Promise = require('bluebird')
|
import Promise from 'bluebird'
|
||||||
const nodeUrl = require('url')
|
import nodeUrl from 'node:url'
|
||||||
const buyan = require('bunyan')
|
import buyan from 'bunyan'
|
||||||
const net = require('net')
|
import net from 'node:net'
|
||||||
const tls = require('tls')
|
import tls from 'node:tls'
|
||||||
const EventEmitter = require('events')
|
import { EventEmitter } from 'node:events'
|
||||||
|
import Connection from './connection.js'
|
||||||
|
import { getNextPortFactory } from './helpers/find-port.js'
|
||||||
|
|
||||||
const Connection = require('./connection')
|
export default class FtpServer extends EventEmitter {
|
||||||
const { getNextPortFactory } = require('./helpers/find-port')
|
|
||||||
|
|
||||||
class FtpServer extends EventEmitter {
|
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
super()
|
super()
|
||||||
this.options = Object.assign(
|
this.options = Object.assign(
|
||||||
@@ -193,4 +192,3 @@ class FtpServer extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = FtpServer
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
// 100 - 199 :: Remarks
|
// 100 - 199 :: Remarks
|
||||||
100: 'The requested action is being initiated',
|
100: 'The requested action is being initiated',
|
||||||
110: 'Restart marker reply',
|
110: 'Restart marker reply',
|
||||||
|
|||||||
Reference in New Issue
Block a user