Node-RED FTP/SFTP Client
node-red-contrib-ftp is a Node-RED package providing nodes for interacting with FTP and SFTP servers. It enables Node-RED flows to perform various file operations such as listing, getting, putting, appending, deleting, and creating directories on remote servers. The package includes an 'ftp in' node for standard FTP operations and an 'sftp in' node for secure file transfer via SFTP. As of version 0.0.8, it integrates directly into the Node-RED editor palette, offering a visual way to manage file transfers. Node-RED contrib packages typically follow the Node-RED release cycle, but individual package updates vary. Key differentiators include its tight integration with Node-RED's flow-based programming model, allowing for easy automation of file transfer tasks within larger workflows without writing custom code.
Common errors
-
Error: connect ECONNREFUSED <host>:<port>
cause The Node-RED instance could not establish a connection to the specified FTP/SFTP server. This often means the server address or port in the configuration node is incorrect, the server is down, or a firewall is blocking the connection from the Node-RED host.fixVerify the host and port in your FTP/SFTP configuration node. Check if the server is running and accessible from the machine hosting Node-RED. Review local and network firewall rules. -
530 Login incorrect.
cause The username or password provided in the FTP/SFTP configuration node is incorrect, or the specified user lacks permission to access the server.fixDouble-check the username and password in your FTP/SFTP configuration node. Ensure the credentials are valid for the target server and that the user has appropriate access rights for the attempted operations. -
Error: No such file or directory
cause The specified remote `msg.filename` or local `msg.localFilename` (if used) does not exist for the attempted operation (e.g., GET, DELETE, APPEND to a non-existent file).fixVerify the exact path and filename for both remote and local files. For local files, ensure the Node-RED process has appropriate read/write permissions to the specified directory.
Warnings
- gotcha This package provides Node-RED 'contrib' nodes. It must be installed into a Node-RED runtime environment and is configured visually in the flow editor, not used as a programmatic JavaScript library. Attempting to `require()` or `import` symbols will fail.
- gotcha FTP and SFTP server connection details (host, port, credentials) are managed within shared configuration nodes. Incorrect, incomplete, or missing configuration will lead to connection failures and errors in your flow.
- gotcha Operations like GET, PUT, and APPEND require both `msg.filename` (the path/name of the file on the remote server) and `msg.localFilename` (the path/name of the file on the local machine running Node-RED, or a Buffer). Mismatched or missing properties will cause errors.
- gotcha The package version 0.0.8 indicates a relatively early stage of development. Users should be aware that future versions, especially before a 1.0.0 release, might introduce breaking changes more frequently than mature libraries.
Install
-
npm install node-red-contrib-ftp -
yarn add node-red-contrib-ftp -
pnpm add node-red-contrib-ftp
Imports
- ftp in node
import { ftpIn } from 'node-red-contrib-ftp'Install via `npm install node-red-contrib-ftp` in your Node-RED user directory, then drag the 'ftp in' node from the Node-RED palette into your flow.
- sftp in node
const sftp = require('node-red-contrib-ftp').sftpInstall via `npm install node-red-contrib-ftp` in your Node-RED user directory, then drag the 'sftp in' node from the Node-RED palette into your flow.
- ftp config node
Hardcoding FTP server credentials directly within individual 'ftp in' node instances or `msg` objects.
Configure a shared 'ftp' configuration node (accessible via 'Add new ftp config...' when editing an 'ftp in' node) to define connection parameters (host, port, user, password) for multiple FTP operations.
Quickstart
[{"id":"91039113.5ae0b8","type":"debug","z":"e052b363.bcca48","name":"Output Debug","active":true,"console":"false","complete":"payload","x":494,"y":72,"wires":[]},{"id":"ebf6cb8.83c77b8","type":"inject","z":"e052b363.bcca48","name":"Trigger Delete","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":114,"y":141,"wires":[["18704d55.fa8d63"]]},{"id":"18704d55.fa8d63","type":"function","z":"e052b363.bcca48","name":"Set Filename for Delete","func":"msg.filename = 'test.csv';\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":141,"wires":[["6f4f3dda.a20a7c"]]},{"id":"6f4f3dda.a20a7c","type":"ftp in","z":"e052b363.bcca48","ftp":"a7676b1a.e9714","operation":"delete","filename":"","localFilename":"","name":"Delete Remote File","x":440,"y":143,"wires":[["be82074.47a8878"]]},{"id":"8e30f382.5971f8","type":"inject","z":"e052b363.bcca48","name":"Trigger List","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":108,"y":67,"wires":[["be82074.47a8878"]]},{"id":"be82074.47a8878","type":"ftp in","z":"e052b363.bcca48","ftp":"a7676b1a.e9714","operation":"list","filename":"","localFilename":"","name":"List Remote Files","x":276,"y":68,"wires":[["91039113.5ae0b8"]]},{"id":"a7676b1a.e9714","type":"ftp","z":"","host":"${process.env.FTP_HOST ?? 'YOUR_FTP_HOST'}","port":"21","secureOptions":"","user":"${process.env.FTP_USERNAME ?? 'YOUR_USERNAME'}","connTimeout":"","pasvTimeout":"","keepalive":""}]