ftp-tail
v2.1.1
Published
A lightweight module to tail files over FTP or SFTP.
Downloads
221
Readme
ftp-tail
About
Need to tail a file on a remote server? ftp-tail should be able to help!
Motivation
To collect the data we needed to build SquadJS, a scripting framework for Squad servers, we found we needed to tail the Squad server's log files. As a result of this, it became a requirement that SquadJS must be installed on the same machine as the Squad server, however, this prevented anyone using rented Squad server instances from using SquadJS. Thus, we endeavoured to make it possible for these logs files to be streamed over the FTP and SFTP servers provided by most hosts - ftp-tail is the outcome of this and we have opened-sourced it for others to benefit from.
Usage
FTP
import { FTPTail } from 'ftp-tail';
(async () => {
// Initiate FTPTail...
const tailer = new FTPTail(
{
ftp: {
// basic-ftp's .access options.
host: "xxx.xxx.xxx.xxx",
user: "user",
password: "password",
// As well as...
timeout: 5 * 1000, // Timeout (optional).
encoding: 'utf8' // Encoding (optional).
},
fetchInterval: 0, // Delay between polls.
log: true // Enable logging (also accepts logging function).
}
);
// Do something with the lines, e.g. log them.
tailer.on('line', console.log);
// Watch the file...
await tailer.watch('/SquadGame.log');
// Unwatch the file...
await tailer.unwatch();
})();
SFTP
import { SFTPTail } from 'ftp-tail';
(async () => {
// Initiate FTPTail...
const tailer = new SFTPTail(
{
ftp: {
// ssh2-sftp-client's .connect options.
host: "xxx.xxx.xxx.xxx",
username: "user",
password: "password",
},
fetchInterval: 0, // Delay between polls.
log: true // Enable logging (also accepts logging function).
}
);
// Do something with the lines, e.g. log them.
tailer.on('line', console.log);
// Watch the file...
await tailer.watch('/SquadGame.log');
// Unwatch the file...
await tailer.unwatch();
})();
Credits
The logic behind ftp-tail was originally proposed, designed and implemented by awn.gg - ftp-tail is an open-sourced re-implementation of their efforts.