SSH Plugin for Cordova to make connections and execute remote commands with the JSch library for Android.
Contributions are welcome.
- Android
cordova plugin add cordova-plugin-ssh-connect- window.cordova.plugins.sshConnect.connect
- window.cordova.plugins.sshConnect.executeCommand
- window.cordova.plugins.sshConnect.disconnect
sshConnect.connect('user', 'password', 'host', port, function(success) {...}, function(failure) {...})Params
user- Host username.password- Host password.host- Hostname or IP address.port- SSH port number.
Success Response
- Return a
booleanvalue.
Failure Response
- Return an error message.
sshConnect.executeCommand('command', function(success) {...}, function(failure) {...})Params
command- The SSH command you want to execute in the remote host.
Success Response
- Return a
stringwith the printed text on the remote console.
Failure Response
- Return an error message.
sshConnect.disconnect(function(success) {...}, function(failure) {...})Params
- No params are provided.
Success Response
- Return a
booleanvalue.
Failure Response
- Return an error message.
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,
function(resp) {
if (resp) {
window.cordova.plugins.sshConnect.executeCommand('ls -l', success, failure);
window.cordova.plugins.sshConnect.disconnect(success, failure);
}
}
, failure);npm install @ionic-native/ssh-connectDefine it at app.module.ts
import { SSHConnect } from '@ionic-native/ssh-connect/ngx';
@NgModule({
...
providers: [
SSHConnect
],
...
})Ionic wrapper functions returns promises, use them as follows:
import { SSHConnect } from '@ionic-native/ssh-connect/ngx';
constructor(private sshConnect: SSHConnect) { }
...
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));There is an example to be able to use the methods in Ionic:
const connected = await this.sshConnect.connect('MyUser', 'MyPassword', '0.0.0.0', 22);
if (connected) {
this.sshConnect.executeCommand('ls -l')
.then(resp => {
console.log(resp);
})
.catch(error => {
console.error(error);
});
this.sshConnect.disconnect();
}- Add iOS support.
- Jose Andrés Pérez Arévalo, (https://github.com/JosePerez27).
View the LICENCE FILE.
Report at GitHub Issues.