Giter VIP home page Giter VIP logo

haxe-sshclient's Introduction

haxe-sshclient

Build Status Release License Contributor Covenant

  1. What is it?
  2. Installation
  3. Using the SSH client
  4. Using the latest code
  5. License

What is it?

A haxelib that provides a basic SSH client to execute commands on remote system. It uses a pre-installed OpenSSH, Putty, or Kitty client under the hood.

All classes are located in the package hx.sshclient or below.

Requirements/Limitations

  • Haxe Version: 4.2.0 or higher
  • Supported Targets: C++, C#, Neko, HashLink, Java/JVM, Python
  • Supported Operating Systems: Linux, MacOS, Windows
  • Preinstalled software: one of the following SSH clients must be installed:
    • Linux/MacOS: OpenSSH (ssh), Putty (plink)
    • Windows: OpenSSH (ssh.exe), Putty (plink.exe), Kitty (klink.exe)
  • Password-based authentication is only supported when using Putty/Kitty.

Installation

  1. MacOS, Linux and Windows 10 or higher have OpenSSH client preinstalled. If you want to use password based authentication install Putty or Kitty client:

  2. Install the library via haxelib using the command:

    haxelib install haxe-sshclient
    
  3. Use the library in your Haxe project:

    • for OpenFL/Lime projects add <haxelib name="haxe-sshclient" /> to your project.xml
    • for free-style projects add -lib haxe-sshclient to your *.hxml file or as command line option when running the Haxe compiler

Using the SSH client

Configuring a Putty/Kitty based SSH client

The following code creates an SSH client backed by Putty/Kitty with default settings that:

  • either uses Putty or Kitty depending on which client was found on the system path - or fails if neither is found
  • uses HostKeyChecking strategy Strict, i.e. only connects to hosts that are already known
  • connects to port 22
import hx.sshclient.PuttySSHClient;
//...
var sshClient = PuttySSHClient.builder()
   .withHostname("myhost")
   .withUsername("myuser")
   .withSecret(Password("mypassword"))
   .build();

The SSH client can be further configured:

import hx.sshclient.PuttySSHClient;
//...
var sshClient = PuttySSHClient.builder()
   .withHostname("myhost")
   .withPort(2222) // use a different port
   .withUsername("myuser")
   .withSecret(IdentityFile("C:\\Users\\myser\\mykey.ppk")) // use a private key for autentication
   .withHostKeyChecking(AcceptNew) // allow connection to new hosts but prevent connections to known hosts with mismatching host keys
   .withExecutable("C:\\apps\\network\\putty\\plink.exe") // specify the client binary to be used
   .build();

Configuring an OpenSSH based SSH client

The following code creates an SSH client backed by OpenSSH with default settings that:

  • either uses an OpenSSH client or fails if not found on the system path
  • uses HostKeyChecking strategy Strict, i.e. only connects to hosts that are already known
  • connects to port 22
import hx.sshclient.OpenSSHClient;
//...
var sshClient = OpenSSHClient.builder()
   .withHostname("myhost")
   .withUsername("myuser")
   .withSecret(IdentityFile("/home/myuser/ssh/id_rsa")) // use a private key for authentication
   .build();

The SSH client can be further configured:

import hx.sshclient.OpenSSHClient;
//...
var sshClient = PuttySSHClient.builder()
   .withHostname("myhost")
   .withPort(2222) // use a different port
   .withUsername("myuser")
   .withHostKeyChecking(AcceptNew) // allow connection to new hosts but prevent connections to known hosts with mismatching host keys
   .withExecutable("/opt/openssh/bin/ssh") // specify the client binary to be used
   .build();

Executing a remote command via SSH

Once you have created an ssh client object you can execute remote commands:

var cmd = sshClient.execute("whoami");
cmd.awaitSuccess(5000); // wait 5 seconds for a successful response, throws an exception otherwise
var output = cmd.stdout.readAll().trim(); // retrieve the output of the executed command
trace('result: ${output}');

Using the latest code

Using haxelib git

haxelib git haxe-sshclient https://github.com/vegardit/haxe-sshclient main D:\haxe-projects\haxe-sshclient

Using Git

  1. check-out the main branch

    git clone https://github.com/vegardit/haxe-sshclient --branch main --single-branch D:\haxe-projects\haxe-sshclient
  2. register the development release with Haxe

    haxelib dev haxe-sshclient D:\haxe-projects\haxe-sshclient

License

All files are released under the Apache License 2.0.

Individual files contain the following tag instead of the full license text:

SPDX-License-Identifier: Apache-2.0

haxe-sshclient's People

Contributors

dependabot[bot] avatar sebthom avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.