mideo / sssh   0.0.3

GitHub

Simple scala ssh library

Scala versions: 2.12 2.11

sssh

Build Status

Maven Central

A Simple scala ssh library

import java.io.InputStream
import com.typesafe.config.ConfigFactory

object main extends App {
 //Create credentials from config
  val configString =
    """
    ssh {
      credentials = [
        {
          alias = testhost
          host = myhostname
          user = username
          password = changeme
        },
        {
          alias = testhost1
          host = myhostname1
          user = username1
          identity = "path/to/key.pem"
        }
      ]
    }
    """
 
  sssh.credentials = sssh.Credentials.from(ConfigFactory.load("default.conf"))
  
  //or configLike String 
  sssh.credentials = sssh.Credentials.from(ConfigFactory.parseString(configString))
  
  //or Create credentials directly
  sssh.credentials = Credential("testAlias", "testHost", "user", Some("pass"), Some(Paths.get(".ssh/key.pem"))
 
    
  //execute command
  sssh.execute("pwd")
  
  //execute scpFrom remote file
   sssh.scpFrom("wget-log")
  
  //or Create credentials directly from List
  sssh.credentials = List(Credential("testAlias", "testHost", "user", Some("pass"), Some(Paths.get("PATH/To/key.pub"))), Credential("testAlias1", "testHost1", "user1", Some("pass1"), None))
  
  //execute command on single host
  sssh.execute("pwd", "testAlias")

  //execute scpTo for file in current working directory
  sssh.scpTo("build.sbt")
  
  //execute scpTo from input stream 
  val in: InputStream = getClass.getClassLoader.getResourceAsStream("default.conf")
  sssh.scpTo("default.conf", in)

  //execute sudo command
  sssh.sudo("whoami")
}