惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
D
Docker
J
Java Code Geeks
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
腾讯CDC
罗磊的独立博客
U
Unit 42
爱范儿
爱范儿
Vercel News
Vercel News
MyScale Blog
MyScale Blog

6Jyc5p+a

【笔记】HermesAgent学习笔记 【笔记】DeepSeekHarness学习笔记 【笔记】Rollup的PluginBabel插件 【笔记】Rollup学习笔记 【笔记】Gulp的BrowserSync插件 【笔记】Tapable学习笔记 【笔记】Highlight.js学习笔记 【笔记】Marked学习笔记 【笔记】Webpack通过schema-utils实现Loader参数校验 【笔记】Webpack实现TreeShaking 【笔记】Webpack的WebpackBundleAnalyzer插件 【代码】校验信用卡号码 【笔记】Webpack的SpeedMesureWebpackPlugin插件 【笔记】Codex配置Brave浏览器的MCP 【笔记】Webpack的CSSMinimizerWebpackPlugin插件 【笔记】FastNodeManager学习笔记 【笔记】Terser学习笔记 【笔记】Codex配置Wireshark的MCP 【笔记】Codex配置Unity的MCP 【笔记】Codex配置Blender的MCP 【笔记】Codex配置IDEA的MCP 【笔记】Browserslist学习笔记 【笔记】Codex学习笔记 【笔记】MicrosoftStore微软商店学习笔记 【笔记】通过NapCat和AstrBot实现QQ机器人 【笔记】部署NapCat 【笔记】部署AstrBot 【笔记】Poetry学习笔记 【笔记】uv学习笔记 【笔记】Nodejs通过mysql2操作MySQL数据库
【笔记】Node-SSH学习笔记
57uv6Z6g · 2026-08-12 · via 6Jyc5p+a

前言

Node-SSH is an extremely lightweight Promise wrapper for ssh2.(Github

下载依赖

1
npm install -D node-ssh

远程执行Shell命令

src/main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
import { NodeSSH } from "node-ssh";

const sshClient = await new NodeSSH().connect({
host: "",
port: 22,
username: "",
password: ""
});

const result = await sshClient.execCommand("<shell>", { cwd: "/" });
console.log(result.stdout);

sshClient.dispose();

文件上传

../package.json:本地路径
/root/package.json:远程路径

recursive:是否递归上传
concurrency:并发上传文件数,缺省值为10

src/main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { NodeSSH } from "node-ssh";

const sshClient = await new NodeSSH().connect({
host: "",
port: 22,
username: "",
password: ""
});

await sshClient.putFile("../package.json", "/root/package.json", {
recursive: true,
concurrency: 10
});

sshClient.dispose();

文件下载

../package.json:本地路径
/root/package.json:远程路径

src/main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
import { NodeSSH } from "node-ssh";

const sshClient = await new NodeSSH().connect({
host: "",
port: 22,
username: "",
password: ""
});

await sshClient.getFile("../package.json", "/root/package.json");

sshClient.dispose();

完成