Skip to content

node-scpCopy files over SSH, to any server

SFTP when the server has it, the real SCP protocol when it does not. One small API for cloud VMs, OpenWrt routers and network gear.

SFTPSCP

Copy a folder in three lines ​

ts
import { connect } from 'node-scp';

await using client = await connect({ host: 'example.com', username: 'deploy', privateKey });
await client.upload('./dist', '/var/www/app', { recursive: true });
ts
import { upload } from 'node-scp';

await upload('./dist', 'deploy@example.com:/var/www/app', { recursive: true, privateKey });
sh
npx node-scp -r ./dist deploy@example.com:/var/www/app
yaml
- uses: maitrungduc1410/node-scp-async@v1
  with:
    host: ${{ secrets.DEPLOY_HOST }}
    username: deploy
    private-key: ${{ secrets.DEPLOY_KEY }}
    source: dist/
    target: /var/www/app

Works with the servers you actually have ​

Pick a server to see what node-scp does with it.

protocol: 'auto' usesSFTP
client.fsavailable
Directory copiesfiles in parallel

The common case. Nothing to configure.

ts
await connect({ host: 'example.com', username: 'deploy', privateKey });

How it picks the protocol ​

Fast where it matters ​

Uploads to OpenSSH on the same machine, mean of several runs. Most of the gap on small files comes from TCP_NODELAY; the comparison page explains it.

200 files of 4 KiB in 10 directories (lower is better)
node-scp (SFTP)
52 ms
node-scp (SCP)
67 ms
node-ssh
484 ms
ssh2-sftp-client
534 ms
One 16 MiB file (lower is better)
node-scp (SCP)
53 ms
node-scp (SFTP)
57 ms
ssh2-sftp-client
94 ms
node-ssh
104 ms

Released under the MIT License.