Skip to content

Commit ab57e72

Browse files
committed
update documentation
1 parent 8064335 commit ab57e72

4 files changed

Lines changed: 103 additions & 106 deletions

File tree

docs/handler.md

Lines changed: 0 additions & 95 deletions
This file was deleted.

docs/index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ To get an FTP server running quickly, the below code will get you started by all
2020
```{code-block} javascript
2121
const { ftpd } = require('jsftpd')
2222
23-
const server = new ftpd({cnf: {username: 'john', password: 'doe'})
24-
25-
server.on('log', console.log)
26-
server.on('error', console.error)
23+
const server = new ftpd({cnf: {username: 'john', password: 'doe', basefolder: '/tmp'})
2724
2825
server.start()
2926
```

docs/options.md

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Configuration
22

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:
44

55
```{code-block} javascript
6-
new ftpd({tls: {...}, cnf: {...}})
6+
new ftpd({tls: {...}, cnf: {...}, hdl: {...}})
77
```
88

99
* **tls**: TLS options. Takes any option as per node.js tls.createServer
1010
* **cnf**: jsftpd specific configuration items
11+
* **hdl**: jsftpd handler for specific FTP commands
1112

1213
## tls
1314

@@ -284,3 +285,99 @@ Allow the anonymous user to create folders.
284285
```{code-block} javascript
285286
new ftpd({cnf: {allowAnonymousFolderCreate: true}})
286287
```
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+
```

readme.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ To get an FTP server running quickly, the below code will get you started by all
2424
```
2525
const { ftpd } = require('jsftpd')
2626
27-
const server = new ftpd({cnf: {username: 'john', password: 'doe'})
28-
29-
server.on('log', console.log)
30-
server.on('error', console.error)
27+
const server = new ftpd({cnf: {username: 'john', password: 'doe', basefolder: '/tmp'})
3128
3229
server.start()
3330
```
@@ -38,4 +35,5 @@ The full documentation of the project is available [here](https://jsftpd.readthe
3835

3936
The ftpd instance takes an object with two properties that allows for configuring the new instance.
4037
- `tls` property object. Takes any configuration option as per node.js tls.createServer [options](https://nodejs.org/api/tls.html#tlscreateserveroptions-secureconnectionlistener)
41-
- `cnf` property object. Takes jsftpd specific configuration items. See full documentation [here](https://jsftpd.readthedocs.io/en/latest/)
38+
- `cnf` property object. Takes jsftpd specific configuration items. See full documentation [here](https://jsftpd.readthedocs.io/en/latest/options.html#cnf)
39+
- `hdl` property object. Takes handler functions for specific FTP commands. See full documentation [here](https://jsftpd.readthedocs.io/en/latest/options.html#hdl)

0 commit comments

Comments
 (0)