/** @param {import(".").NS } ns */

export async function main(ns) {
    // ns.disableLog('ALL');

    function scanServer(currentServer, previousServer = currentServer) {
        // ns.tprint(currentServer);
        let availableServers = ns.scan(currentServer);

        for (let i = 0; i < availableServers.length; ++i) {
            let nextServer = availableServers[i];

            if (nextServer != currentServer && nextServer != previousServer) {
                let litFiles = ns.ls(nextServer, 'lit');
                ns.tprint(`Download from '${nextServer}': ${litFiles}`);
                if (ns.args[0] && litFiles.length) {
                    ns.scp(litFiles, 'home', nextServer);
                }

                scanServer(nextServer, currentServer);
            }
        }
    }

    scanServer('home');
}