-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ssh: Add new module
ssh
via bind libssh2
Signed-off-by: Jianhui Zhao <[email protected]>
- Loading branch information
Showing
8 changed files
with
1,212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env eco | ||
|
||
local ssh = require 'eco.ssh' | ||
|
||
local ipaddr = '127.0.0.1' | ||
local port = 22 | ||
local username = 'root' | ||
local password = '1' | ||
|
||
local session, err = ssh.new(ipaddr, port, username, password) | ||
if not session then | ||
print('new session fail:', err) | ||
return | ||
end | ||
|
||
local data, exit_code, exit_signal = session:exec('uptime') | ||
if not data then | ||
print('exec fail:', exit_code) | ||
return | ||
end | ||
|
||
if exit_signal then | ||
print('Got signal:', exit_signal) | ||
else | ||
print('Exit:', exit_code) | ||
print('Output:', data) | ||
end | ||
|
||
session:free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env eco | ||
|
||
local ssh = require 'eco.ssh' | ||
|
||
local ipaddr = '127.0.0.1' | ||
local port = 22 | ||
local username = 'root' | ||
local password = '1' | ||
|
||
local session, err = ssh.new(ipaddr, port, username, password) | ||
if not session then | ||
print('new session fail:', err) | ||
return | ||
end | ||
|
||
-- receive as a string returned | ||
local data, err = session:scp_recv('/etc/os-release') | ||
if not data then | ||
print('recv fail:', err) | ||
return | ||
end | ||
|
||
print(data) | ||
|
||
-- receive to a local file | ||
local n, err = session:scp_recv('/etc/os-release', '/tmp/os-release') | ||
if not n then | ||
print('recv fail:', err) | ||
return | ||
end | ||
|
||
print('Got', n, 'bytes, stored into "/tmp/os-release"') | ||
|
||
session:free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env eco | ||
|
||
local ssh = require 'eco.ssh' | ||
|
||
local ipaddr = '127.0.0.1' | ||
local port = 22 | ||
local username = 'root' | ||
local password = '1' | ||
|
||
local session, err = ssh.new(ipaddr, port, username, password) | ||
if not session then | ||
print('new session fail:', err) | ||
return | ||
end | ||
|
||
-- send a string | ||
local ok, err = session:scp_send('12345\n', '/tmp/test1') | ||
if not ok then | ||
print('send fail:', err) | ||
return | ||
end | ||
|
||
-- send a file | ||
local ok, err = session:scp_sendfile('test', '/tmp/test2') | ||
if not ok then | ||
print('send fail:', err) | ||
return | ||
end | ||
|
||
session:free() |
Oops, something went wrong.