xxxxxxxxxx
const { exec } = require('child_process');
function runCommand(command) {
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
}
// You can run any command using this function.
// Make sure to replace `localhost` with your TFTP server's address,
// and replace `local-file.txt` and `remote-file.txt` with your actual filenames.
// Get a file
runCommand('tftp localhost -c get remote-file.txt local-file.txt');
// Put a file
runCommand('tftp localhost -c put local-file.txt remote-file.txt');
xxxxxxxxxx
var tftp = require('tftp');
// Initialize the client
var client = tftp.createClient({
host: "localhost",
port: 1234 //port number where TFTP server is running
});
// Put a file on the server
client.put("local-file.txt", "remote-file.txt", function(err) {
if (err) {
console.error(err);
} else {
console.log("File uploaded successfully");
}
});
// Get a file from the server
client.get("remote-file.txt", "local-file.txt", function(err) {
if (err) {
console.error(err);
} else {
console.log("File downloaded successfully");
}
});