cordova-plugin-ssh-connect-key
v1.1.5
Published
Cordova plugin to make connections and execute commands through SSH
Downloads
16
Maintainers
Readme
SSH Connect
SSH Plugin for Cordova to make connections and execute remote commands with the JSch library for Android.
Contributions are welcome.
Supported Platforms
- Android
Install
cordova plugin add cordova-plugin-ssh-connect-key
Methods
- window.cordova.plugins.sshConnect.connect
- window.cordova.plugins.sshConnect.executeCommand
- window.cordova.plugins.sshConnect.disconnect
Usage
Connect Method
sshConnect.connect('user', 'password', 'host', port, key, function(success) {...}, function(failure) {...})
Params
user
- Host username.password
- Host password.host
- Hostname or IP address.port
- SSH port number.key
- Private ssh key.
Success Response
- Return a
boolean
value.
Failure Response
- Return an error message.
Execute Command Method
sshConnect.executeCommand('command', function(success) {...}, function(failure) {...})
Params
command
- The SSH command you want to execute in the remote host.
Success Response
- Return a
string
with the printed text on the remote console.
Failure Response
- Return an error message.
Disconnect Method
sshConnect.disconnect(function(success) {...}, function(failure) {...})
Params
- No params are provided.
Success Response
- Return a
boolean
value.
Failure Response
- Return an error message.
Example Usage
Now here is an example to be able to use the methods:
var success = function (resp) {
alert(resp);
}
var failure = function (error) {
alert(error);
}
window.cordova.plugins.sshConnect.connect('MyUser', 'MyPassword', '0.0.0.0', 22, key,
function(resp) {
if (resp) {
window.cordova.plugins.sshConnect.executeCommand('ls -l', success, failure);
window.cordova.plugins.sshConnect.disconnect(success, failure);
}
}
, failure);
Usage
...
this.sshConnect.connect('user', 'password', 'host', port) .then(resp => console.log(resp)) .catch(error => console.error(err));
this.sshConnect.executeCommand('command') .then(resp => console.log(resp)) .catch(error => console.error(err));
this.sshConnect.disconnect() .then(resp => console.log(resp)) .catch(error => console.error(err));
### Example Usage
There is an example to be able to use the methods in Ionic:
```typescript
const connected = await this.sshConnect.connect('MyUser', 'MyPassword', '0.0.0.0', 22, key);
if (connected) {
this.sshConnect.executeCommand('ls -l')
.then(resp => {
console.log(resp);
})
.catch(error => {
console.error(error);
});
this.sshConnect.disconnect();
}
TODO
- Add iOS support.
Author
- Jose Andrés Pérez Arévalo, Denis Spasyuk.
Licence
View the LICENCE FILE.
Issues
Report at GitHub Issues.