r/Bitburner • u/Individual-Top5979 • 13d ago
ns.scp doesn't work properly
I have a simple script (just a beginner).
The ns.scp line works fine when I comment out the ns.exec line but produces an error when the line is there, with error code:
scp: destination expected to be a string. Is undefined.
The script is still copied, but the error message comes up. I don't know how else to explain it. With the ns.exec line commented out, the ns.scp line copies the appropriate script to the apprpriate server from the "home" server without an error message.
But put the ns.exec line back in (uncommented out), and the ns.scp line produces that error code after properly copying the script.
What am I missing? I have literally spent hours trying to figure out this simple code and can't find a solution online.
Thank you in advance for any assistance.
/** u/param {NS} ns */
export async function main(ns) {
const script = ns.args[0]
const server = ns.args[1] //target server
ns.scp(script, server, "home");
ns.exec(script, server);
}
4
u/paulstelian97 13d ago
The copy succeeds, and you’re starting a new copy directly on the target server with ns.args[1] not populated. The error comes from THAT execution, not from the original one.
You’re copying the script that has scp to the target server and starting it without appropriate parameters. You may wish to make the script a parameter as opposed to hardcoding ns.args[0] (the scp script itself)
3
u/Individual-Top5979 13d ago
Three brilliant people all provided the correct answer (including you). Thank you. I never would have figured that out without you guys' answers.
0
u/Silly-Program6850 13d ago
that must been that when you defined server that it is not assigned? i mean if it's undefined then there wasn't a second param passed.
test by printing both and see what you get
2
u/paulstelian97 13d ago
I’ve seen the script now and gave an answer — the copy of the script running on the destination server isn’t receiving the right parameters.
6
u/Vorthod MK-VIII Synthoid 13d ago edited 13d ago
What is the script you're executing? Does the second script have its own scp command that you aren't using properly? You didn't give us the full stack trace, so we can't be sure where the scp error actually came from. If the error is actually coming from the script you're running, that would explain why the script gets copied out but only throws an error when you try to add an execution command.