{"id":12138,"library":"tftp","title":"TFTP Client and Server","description":"This module provides a full-featured streaming TFTP (Trivial File Transfer Protocol) client and server for Node.js. It supports several TFTP RFCs (1350, 2347, 2348, 2349, 3617, 7440) and de facto extensions like rollover and windowsize, which address TFTP's inherent 32MB file size limit and slow lock-step transfer mechanism. The current stable version is 0.1.2. Developed for Node.js versions 0.10 and newer, it integrates with Node.js streams for easy file transfers. However, the README clearly states that TFTP is an obsolete legacy protocol, generally unsuitable for internet transfers due to UDP packet loss, and recommends FTP for most use cases. Its primary differentiation is providing a complete TFTP solution within Node.js, including performance-boosting extensions, despite the protocol's limitations. The package does not appear to have an active release cadence, with the last known update being in 2015.","status":"abandoned","version":"0.1.2","language":"javascript","source_language":"en","source_url":"git://github.com/gagle/node-tftp","tags":["javascript","tftp","client","stream"],"install":[{"cmd":"npm install tftp","lang":"bash","label":"npm"},{"cmd":"yarn add tftp","lang":"bash","label":"yarn"},{"cmd":"pnpm add tftp","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module, intended for use with `require()`. Direct ES module `import` statements for named exports will not work as expected.","wrong":"import { createClient } from 'tftp'; // Incorrect for CommonJS module\nconst client = createClient();","symbol":"TFTP client instantiation","correct":"const tftp = require('tftp');\nconst client = tftp.createClient();"},{"note":"The `createServer` method is a property of the main module export. Ensure you are using `require('tftp')` to get the module object.","wrong":"import tftp from 'tftp';\nconst server = tftp.createServer(); // Incorrect if 'tftp' is not the default export containing 'createServer'","symbol":"TFTP server instantiation","correct":"const tftp = require('tftp');\nconst server = tftp.createServer();"},{"note":"The `get` method is invoked on an instantiated client object. It returns a stream, which should have error and timeout handlers.","wrong":"const { get } = require('tftp').createClient(); // 'get' is a method on the client instance, not a named export.","symbol":"TFTP client GET operation","correct":"const tftp = require('tftp');\nconst client = tftp.createClient();\nconst get = client.get('remoteFile.txt', { remoteAddress: '127.0.0.1', remotePort: 69 });\nget.on('error', (err) => console.error('GET error:', err));\nget.on('timeout', () => console.error('GET timeout.'));"}],"quickstart":{"code":"const tftp = require('tftp');\nconst fs = require('fs');\n\n// --- TFTP Server Example ---\nconst server = tftp.createServer();\nserver.on('error', (err) => {\n  console.error('Server error:', err.message);\n});\nserver.on('get', (req, respond) => {\n  console.log(`Server received GET request for: ${req.file} from ${req.remoteAddress}:${req.remotePort}`);\n  const filePath = `./server_files/${req.file}`;\n  fs.access(filePath, fs.constants.F_OK, (err) => {\n    if (err) {\n      console.error(`File not found: ${filePath}`);\n      return req.error('File not found');\n    }\n    respond(fs.createReadStream(filePath));\n  });\n});\nserver.on('put', (req, readStream) => {\n  console.log(`Server received PUT request for: ${req.file} from ${req.remoteAddress}:${req.remotePort}`);\n  const filePath = `./server_files/${req.file}`;\n  const writeStream = fs.createWriteStream(filePath);\n  readStream.pipe(writeStream);\n  readStream.on('end', () => {\n    console.log(`File ${req.file} saved on server.`);\n  });\n  readStream.on('error', (err) => {\n    console.error(`Error saving file ${req.file} on server:`, err.message);\n  });\n});\nserver.listen(69, () => {\n  console.log('TFTP server listening on port 69...');\n});\n\n// --- TFTP Client Example (after server is running) ---\n// Ensure 'test_file.txt' exists in a 'client_files' directory or similar for PUT\n// Ensure 'server_files/remote_file.txt' exists for GET\n\n// To run this example:\n// 1. Create a directory named 'server_files'\n// 2. Place a file named 'remote_file.txt' inside 'server_files'\n// 3. Create a directory named 'client_downloads'\n\nconst client = tftp.createClient();\nconst remoteHost = '127.0.0.1';\n\n// Client GET operation\nconst getRequest = client.get('remote_file.txt', { remoteAddress: remoteHost, remotePort: 69 });\nconst downloadPath = './client_downloads/downloaded_file.txt';\nconst writeStream = fs.createWriteStream(downloadPath);\n\ngetRequest.on('error', (err) => {\n  console.error('Client GET error:', err.message);\n  process.exit(1);\n});\ngetRequest.on('timeout', () => {\n  console.error('Client GET timed out.');\n  process.exit(1);\n});\ngetRequest.on('end', () => {\n  console.log(`File downloaded to ${downloadPath}`);\n});\ngetRequest.pipe(writeStream);\n\n// // Client PUT operation (uncomment to test PUT)\n// const uploadPath = './client_files/upload_me.txt'; // Make sure this file exists\n// const putRequest = client.put('uploaded_file.txt', { remoteAddress: remoteHost, remotePort: 69 });\n// const readStream = fs.createReadStream(uploadPath);\n\n// putRequest.on('error', (err) => {\n//   console.error('Client PUT error:', err.message);\n//   process.exit(1);\n// });\n// putRequest.on('timeout', () => {\n//   console.error('Client PUT timed out.');\n//   process.exit(1);\n// });\n// putRequest.on('end', () => {\n//   console.log(`File uploaded from ${uploadPath}`);\n// });\n// readStream.pipe(putRequest);\n","lang":"javascript","description":"This quickstart demonstrates setting up a basic TFTP server to handle GET and PUT requests and a client to download a file from it. It showcases the streaming interface for file transfers and includes basic error handling for both server and client operations. To run this, create 'server_files' and 'client_downloads' directories, and place a 'remote_file.txt' in 'server_files'."},"warnings":[{"fix":"Avoid using TFTP for any scenario where network reliability is not guaranteed (e.g., over the public internet). Consider FTP, SFTP, or HTTP for more reliable transfers.","message":"TFTP is an obsolete legacy protocol built on UDP. It is highly susceptible to packet loss and is explicitly not recommended for use over the internet. FTP or other robust protocols should be used instead for remote file transfers.","severity":"gotcha","affected_versions":">=0.1.2"},{"fix":"Do NOT increase the default window size (4) when running this module on Windows. Test thoroughly if custom window sizes are absolutely necessary on this platform.","message":"On Windows platforms, there's a known issue with UDP packet buffering that can lead to dropped packets, especially when using TFTP's 'windowsize' option larger than 6 blocks. This can severely degrade transfer reliability and potentially cause failures.","severity":"gotcha","affected_versions":">=0.1.2 (on Windows)"},{"fix":"Be aware of these limitations. For large file transfers or high-performance needs, TFTP is generally unsuitable. Ensure both client and server support and negotiate extensions for files larger than 32MB.","message":"Without specific TFTP extensions (like blocksize, rollover, or windowsize), the original RFC 1350 limits file transfers to 32MB. Even with extensions, performance is inherently slow due to the lock-step (one acknowledgement per packet) nature of the protocol.","severity":"gotcha","affected_versions":">=0.1.2"},{"fix":"Ensure port 69/UDP is open and available on the server's host. Run the application with sufficient privileges to bind to network ports. Check for other services already using port 69.","message":"The package's core TFTP functionality operates over UDP port 69 by default. Deploying this server requires appropriate network configuration (e.g., firewall rules) to allow UDP traffic on this port. Conflicting services or insufficient permissions can prevent the server from binding.","severity":"breaking","affected_versions":">=0.1.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Identify and stop the conflicting process, or configure the TFTP server to listen on a different, available port using the `server.listen(PORT)` method.","cause":"The default TFTP server port (UDP 69) is already in use by another process on the system, or the server was not properly shut down from a previous run.","error":"Error: bind EADDRINUSE :::69"},{"fix":"Verify that the file path requested by the client is correct and that the file exists on the server. Ensure the server process has read access to the file and its containing directory.","cause":"The requested file does not exist on the TFTP server at the specified path, or the server lacks read permissions for that file.","error":"Error: Client GET error: File not found"},{"fix":"Ensure you are importing the module using `const tftp = require('tftp');` and then accessing `tftp.createClient()` or `tftp.createServer()`.","cause":"This error typically occurs if the module is imported using ES module syntax (`import`) instead of CommonJS `require()`, or if the module's main export structure has been misunderstood.","error":"TypeError: tftp.createClient is not a function"}],"ecosystem":"npm"}