Skip to content

StefanAlexandruBogdan/node-tftp-server

 
 

Repository files navigation

TFTP Server

You want to serve files using the Trivial File Transfer Protocol? Well, then this module might be the one you are looking for.

API

const TFTP = require('tftp-server');

Method: createServer()

const srv = TFTP.createServer();

Creates a new TFTP server and returns an instance of TFTPServer.

Class: TFTPServer

Don't instantiate this class directly. You should use the factory function TFTP.createServer().

Method: register()

const handle = srv.register([filter, ]handler);

Registers a new request handler.

The optional filter can be a string or a regular expression. The handler will only be called if the filter matches. If filter is omitted, the handler will be called on every request.

The handler is a function with the following interface: (req, res, next) => {...}. The parameters:

  • req: An object describing the current request:
    • req.filename: The requested file name. This comes in handy if filter is omitted or a regular expression.
    • req.mode: The stated transmission mode.
  • res: A function that awaits a Buffer as the first argument. If it is called, the buffer is transmitted to the client. No other handlers will be called.
  • next: A function that takes an optional argument. If the argument is an instance of Error, an ERROR packet is sent to the client. If the argument is omitted, the next registered handler is called.

If no matching handler is found that called res, a "File not found" error is sent to the client.

Method: unregister()

srv.unregister(handle);

This removes the handler addressed by the given handle.

Method: bind()

srv.bind(options);

Binds the server. For further details about options please have a look into the Node.js API docs for UDP/Datagram.

Method: destroy()

srv.destroy([cb]);

Closes all connections and sockets.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%