@xtail/ssh
Version:
X-Tail SSH 库,包含 SSH 连接服务器的类和工具方法等
33 lines (32 loc) • 792 B
JavaScript
import n from "ssh2-promise";
import { SSHErrorMiddleware as c } from "../middlewares/ssh-error.js";
const a = async (t, r = 'echo "Connection test"') => {
var o;
const e = new n(t);
try {
await e.connect();
const s = await e.exec(r);
return {
success: !0,
server: `${t.host}:${t.port ?? 22}`,
message: "连接成功",
detail: (o = s.stdout) == null ? void 0 : o.trim()
};
} catch (s) {
return Promise.reject(s);
} finally {
await e.close().catch(() => {
});
}
}, u = async (t, r = {}) => {
const { testCommand: e, timeout: o } = {
testCommand: 'echo "Connection test"',
timeout: 5e3,
...r
};
return await c(a, { config: t, timeout: o })(t, e);
};
export {
a as testConn,
u as testConnWithErrMiddleware
};