bitburner-src/markdown/bitburner.ns.scp.md

71 lines
2.1 KiB
Markdown
Raw Normal View History

<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [NS](./bitburner.ns.md) &gt; [scp](./bitburner.ns.scp.md)
## NS.scp() method
Copy file between servers.
**Signature:**
```typescript
scp(files: string | string[], destination: string, source?: string): boolean;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| files | string \| string\[\] | Filename or an array of filenames of script/literature files to copy. Note that if a file is located in a subdirectory, the filename must include the leading <code>/</code>. |
| destination | string | Hostname of the destination server, which is the server to which the file will be copied. |
| source | string | _(Optional)_ Hostname of the source server, which is the server from which the file will be copied. This argument is optional and if its omitted the source will be the current server. |
**Returns:**
boolean
True if the file is successfully copied over and false otherwise. If the files argument is an array then this function will return false if any of the operations failed.
## Remarks
RAM cost: 0.6 GB
Copies a script or literature (.lit) file(s) to another server. The files argument can be either a string specifying a single file to copy, or an array of strings specifying multiple files to copy.
## Example 1
```ts
// NS1:
//Copies foo.lit from the helios server to the home computer:
scp("foo.lit", "home", "helios");
//Tries to copy three files from rothman-uni to home computer:
files = ["foo1.lit", "foo2.script", "foo3.script"];
scp(files, "home", "rothman-uni");
```
## Example 2
```ts
// NS2:
//Copies foo.lit from the helios server to the home computer:
ns.scp("foo.lit", "home", "helios" );
//Tries to copy three files from rothman-uni to home computer:
files = ["foo1.lit", "foo2.script", "foo3.script"];
ns.scp(files, "home", "rothman-uni");
```
## Example 3
```ts
//ns2, copies files from home to a target server
const server = ns.args[0];
const files = ["hack.js","weaken.js","grow.js"];
ns.scp(files, server, "home");
```