Skip to content

Commit

Permalink
feat: add supported for listening for ssh events
Browse files Browse the repository at this point in the history
  • Loading branch information
maitrungduc1410 committed Aug 5, 2023
1 parent cd1d4dc commit 09a089c
Show file tree
Hide file tree
Showing 7 changed files with 884 additions and 588 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,36 @@ async function test() {
test()
```

## Events
You can listen for any event [provided by SSH2](https://github.com/mscdex/ssh2#client) during an SSH session by passing `events` to `Connection options`

For example:
```ts
try {
const client = await Client({
host: "server_ip",
port: 22,
username: "username",
tryKeyboard: true,
events: {
"keyboard-interactive": (
name,
instructions,
instructionsLang,
prompts,
finish
) => {
finish(['my_password'])
},
},
});

client.close(); // remember to close connection after you finish
} catch (e) {
console.log(e);
}
```

## Connection options
Below are available options you can pass when connecting to server:
* **agent** - _string_ - Path to ssh-agent's UNIX socket for ssh-agent-based user authentication. **Windows users: set to 'pageant' for authenticating with Pageant or (actual) path to a cygwin "UNIX socket."** **Default:** (none)
Expand Down Expand Up @@ -1485,5 +1515,7 @@ Below are available options you can pass when connecting to server:
* **tryKeyboard** - _boolean_ - Try keyboard-interactive user authentication if primary user authentication method fails. If you set this to `true`, you need to handle the `keyboard-interactive` event. **Default:** `false`

* **username** - _string_ - Username for authentication. **Default:** (none)

* **events** - Object - List of events to listen to. **Default:** (none)
# Support
If you like this project, give me 1 ⭐️
118 changes: 66 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "node-scp",
"title": "SCP module for NodeJS",
"description": "Lightweight, fast and secure SCP function for NodeJS",
"version": "0.0.22",
"version": "0.0.23",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"license": "MIT",
Expand Down Expand Up @@ -35,13 +35,13 @@
"release": "standard-version"
},
"dependencies": {
"ssh2": "^1.11.0"
"ssh2": "^1.14.0"
},
"devDependencies": {
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@types/node": "^16.0.1",
"@types/ssh2": "^1.11.5",
"@types/ssh2": "^1.11.13",
"husky": "^7.0.1",
"standard-version": "^9.3.0",
"typescript": "^4.3.5"
Expand Down
36 changes: 27 additions & 9 deletions src/constant.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export enum errorCode {
generic = 'ERR_GENERIC_CLIENT',
connect = 'ERR_NOT_CONNECTED',
badPath = 'ERR_BAD_PATH',
permission = 'EACCES',
notexist = 'ENOENT',
notdir = 'ENOTDIR'
export enum errorCode {
generic = "ERR_GENERIC_CLIENT",
connect = "ERR_NOT_CONNECTED",
badPath = "ERR_BAD_PATH",
permission = "EACCES",
notexist = "ENOENT",
notdir = "ENOTDIR",
}

export enum targetType {
Expand All @@ -13,5 +13,23 @@ export enum targetType {
writeDir = 3,
readDir = 4,
readObj = 5,
writeObj = 6
}
writeObj = 6,
}

export const CLIENT_EVENTS = new Set([
"banner",
"ready",
"tcp connection",
"x11",
"keyboard-interactive",
"change password",
"error",
"end",
"close",
"timeout",
"connect",
"greeting",
"handshake",
"hostkeys",
"unix connection",
]);
Loading

0 comments on commit 09a089c

Please sign in to comment.