|
1 | 1 | # Configuration |
2 | 2 |
|
3 | | -jsftpd takes an object when a new instance is created. This object can contain two properties: |
| 3 | +jsftpd takes an object when a new instance is created. This object can have different properties: |
4 | 4 |
|
5 | 5 | ```{code-block} javascript |
6 | | -new ftpd({tls: {...}, cnf: {...}}) |
| 6 | +new ftpd({tls: {...}, cnf: {...}, hdl: {...}}) |
7 | 7 | ``` |
8 | 8 |
|
9 | 9 | * **tls**: TLS options. Takes any option as per node.js tls.createServer |
10 | 10 | * **cnf**: jsftpd specific configuration items |
| 11 | +* **hdl**: jsftpd handler for specific FTP commands |
11 | 12 |
|
12 | 13 | ## tls |
13 | 14 |
|
@@ -284,3 +285,99 @@ Allow the anonymous user to create folders. |
284 | 285 | ```{code-block} javascript |
285 | 286 | new ftpd({cnf: {allowAnonymousFolderCreate: true}}) |
286 | 287 | ``` |
| 288 | + |
| 289 | +## hdl |
| 290 | + |
| 291 | +jsftpd can use handler functions instead of reading/writing to the file system for several FTP commands. |
| 292 | + |
| 293 | +```{code-block} javascript |
| 294 | +const handler = { |
| 295 | + upload: async function (...) {}, |
| 296 | + download: async function (...) {}, |
| 297 | + list: async function (...) {}, |
| 298 | + rename: async function (...) {} |
| 299 | +} |
| 300 | +const server = new ftpd({hdl: handler}) |
| 301 | +``` |
| 302 | + |
| 303 | +The following FTP commands are covered by the handlers |
| 304 | + |
| 305 | +* **STOR**: Uploading files to the FTP server |
| 306 | +* **RETR**: Downloading files from the FTP server |
| 307 | +* **LIST**: Listing directory contents on the FTP server |
| 308 | +* **MLSD**: Listing directory contents on the FTP server |
| 309 | +* **RNFR**: Renaming files on the FTP server |
| 310 | +* **RNTO**: Renaming files on the FTP server |
| 311 | + |
| 312 | +### upload |
| 313 | + |
| 314 | +**Name: `upload`**\ |
| 315 | +**Returns: `boolean`** |
| 316 | + |
| 317 | +The upload function takes 5 arguments when being called from jsftpd. It must return `true` on success or `false` on any error handling the file upload. |
| 318 | + |
| 319 | +**username: `string` the user who has uploaded the file**\ |
| 320 | +**path: `string` relative path on the FTP server where the file is stored**\ |
| 321 | +**fileName: `string` the name of the file that is stored**\ |
| 322 | +**data: `Buffer` the file content that is stored**\ |
| 323 | +**offset: `number` the offset of the data received** |
| 324 | + |
| 325 | +```{code-block} javascript |
| 326 | +async upload (username, path, fileName, data, offset) { |
| 327 | + ... |
| 328 | +} |
| 329 | +``` |
| 330 | + |
| 331 | +### download |
| 332 | + |
| 333 | +**Name: `upload`**\ |
| 334 | +**Returns: `Buffer`** |
| 335 | + |
| 336 | +The download function takes 4 arguments when being called from jsftpd. It must return the file content as a `Buffer`. |
| 337 | + |
| 338 | +**username: `string` the user who has uploaded the file**\ |
| 339 | +**path: `string` relative path on the FTP server where the file is stored**\ |
| 340 | +**fileName: `string` the name of the file that is stored**\ |
| 341 | +**data: `Buffer` the file content that is stored**\ |
| 342 | +**offset: `number` the offset of the data received** |
| 343 | + |
| 344 | +```{code-block} javascript |
| 345 | +async upload (username, path, fileName, data, offset) { |
| 346 | + ... |
| 347 | +} |
| 348 | +``` |
| 349 | + |
| 350 | +### list |
| 351 | + |
| 352 | +**Name: `list`**\ |
| 353 | +**Returns: `string`** |
| 354 | + |
| 355 | +The list function takes 3 arguments when being called from jsftpd. It must return the content of the specified directory as a `string`. |
| 356 | + |
| 357 | +**username: `string` the current user**\ |
| 358 | +**path: `string` relative path on the FTP server**\ |
| 359 | +**format: `string` the format of the list reply (MLSD | LIST)** |
| 360 | + |
| 361 | +```{code-block} javascript |
| 362 | +async upload (username, path, format) { |
| 363 | + ... |
| 364 | +} |
| 365 | +``` |
| 366 | + |
| 367 | +### rename |
| 368 | + |
| 369 | +**Name: `rename`**\ |
| 370 | +**Returns: `boolean`** |
| 371 | + |
| 372 | +The rename function takes 4 arguments when being called from jsftpd. It must return `true` on success or `false` on any error handling the file rename. |
| 373 | + |
| 374 | +**username: `string` the current user**\ |
| 375 | +**path: `string` relative path on the FTP server**\ |
| 376 | +**fromName: `string` the current file that needs to be renamed** |
| 377 | +**newName: `string` the new name of the file** |
| 378 | + |
| 379 | +```{code-block} javascript |
| 380 | +async upload (username, path, fromName, newName) { |
| 381 | + ... |
| 382 | +} |
| 383 | +``` |
0 commit comments