• Stars
    star
    194
  • Rank 200,219 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Swift SSH framework that wraps libssh2.

SwiftSH

Build Status Carthage compatible Pods Pod platforms

A Swift SSH framework that wraps libssh2.

Features:

  • Thread-safety
  • SSH shell
  • SSH command
  • SCP
  • SFTP
  • Tests
  • Documentation

๐Ÿ“ฆ Installation

CocoaPods

CocoaPods is the dependency manager for Swift and Objective-C Cocoa projects. It has over ten thousand libraries and can help you scale your projects elegantly.

Add this to your Podfile:

use_frameworks!

pod 'SwiftSH'

Carthage

Carthage builds your dependencies and provides you with binary frameworks, but you retain full control over your project structure and setup.

Add this to your Cartfile:

github "Frugghi/SwiftSH"

๐Ÿ“– Documentation

The API documentation is available here.

๐Ÿ’ป Usage

Import the framework:

import SwiftSH

Execute a SSH command:

let command = Command(host: "localhost", port: 22)
// ...
command.connect()
       .authenticate(.byPassword(username: "username", password: "password"))
       .execute(command) { (command, result: String?, error) in
           if let result = result {
               print("\(result)")
           } else {
               print("ERROR: \(error)")
           }
       }

Open a SSH shell:

let shell = Shell(host: "localhost", port: 22)
// ...
shell.withCallback { (string: String?, error: String?) in
         print("\(string ?? error!)")
     }
     .connect()
     .authenticate(.byPassword(username: "username", password: "password"))
     .open { (error) in
         if let error = error {
             print("\(error)")
         }
     }
// ...
shell.write("ls -lA") { (error) in
    if let error = error {
        print("\(error)")
    }
}
// ...
shell.disconnect()

โš ๏ธ OpenSSL and Libssh2 binaries

SwiftSH includes precompiled binaries of Libssh2 and OpenSSL generated with this script. For security reasons, you are strongly encouraged to recompile the libraries and replace the binaries.

๐Ÿ“„ License LICENSE

SwiftSH is released under the MIT license. See LICENSE for details.