Skip to content

tuzig/cordova-plugin-ssh-connect

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Licence npm npm

SSH Connect

SSH Plugin for Cordova to make connections and execute remote commands with the JSch library for Android & iOS.

Contributions are welcome.

Supported Platforms

  • Android
  • iOS (Experimental)

Install

cordova plugin add https://tuzig.com/tuzig/cordova-plugin-ssh-connect.git

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 - In progress.

Author

Licence

View the LICENCE FILE.

Issues

Report at GitHub Issues.

About

Cordova plugin to make connections and execute commands through SSH

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 50.8%
  • Swift 44.5%
  • JavaScript 4.1%
  • Objective-C 0.6%