An extended and more user-friendly wrapper for the node-ssh package.
对 node-ssh 包进行适当的扩展使其更加易用
Usage(使用)
constopts={host: '',port: 22,password: '',username: 'root'}constssh=awaitSSHClient.connect(opts)constroots=awaitssh.readPath('/')// Establishing a connection is costly - preserve the SSHClient instance for continuous use// Close connection after completing all operations// 建立链接的代价是高昂的, 连续使用请保存 SSHClient 实例// 在完全使用完毕后关闭连接ssh.close()
constopts={host: '',port: 22,password: '',username: 'root'}constssh=awaitSSHClient.connect(opts)// The toProxy method creates a proxy for the ssh object// This proxy intercepts exceptions from async methods and converts them into AsyncFunctionError events// Note: This proxy helps implement custom connection verification// The underlying ssh2 library's close event may not reflect connection status in real-time (can take minutes to trigger after disconnection)// toProxy enables custom connectivity checks after failed operations// 使用 toProxy 方法将会创建 ssh 对象的代理// 此代理会拦截 async 方法抛出的异常转换为错误事件 Exception 中的 AsyncFunctionError// 注意: 此代理是为了帮助用户使用自己的方法检测连接的连通性// node-ssh 底层的 ssh2 库的 close 事件有时候不能实时的反应连接的通断, 会在断网十几分钟后触发,因此// 使用 toProxy 在用户操作失败后使用自定义方式检测连接的连通性constsshProxy=awaitssh.toProxy()constroots=awaitsshProxy.readPath('/')// Establishing a connection is costly - preserve the SSHClient instance for continuous use// Close connection after completing all operations// 建立链接的代价是高昂的, 连续使用请保存 SSHClient 实例// 在完全使用完毕后关闭连接ssh.close()