1.1.1 • Published 5 years ago

cordova-plugin-ssh-connect v1.1.1

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
5 years ago

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

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, function(success) {...}, function(failure) {...})

Params

  • user - Host username.
  • password - Host password.
  • host - Hostname or IP address.
  • port - SSH port number.

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,
    function(resp) {
      if (resp) {
        window.cordova.plugins.sshConnect.executeCommand('ls -l', success, failure);
        window.cordova.plugins.sshConnect.disconnect(success, failure);
      }
    }
  , failure);

Ionic 4 Usage

Install Wrapper

npm install @ionic-native/ssh-connect

Definitions

Define 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));

Example Usage

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();

  }

TODO

  • Add iOS support.

Author

Licence

View the LICENCE FILE.

Issues

Report at GitHub Issues.