Giter VIP home page Giter VIP logo

swift-ssh-client's Introduction

Swift SSH Client

This project provides high-level SSH client interfaces using SwiftNIO SSH.

Requirements

Swift SSH Client is compatible with iOS 13.0+ and macOS 10.5+.

Getting started

SSH is a multiplexed protocol: each SSH connection is subdivided into multiple bidirectional communication channels.

Swift SSH Client reflects this pattern. The first step is to set a connection up:

let connection = SSHConnection(
    host: "my_host",
    port: my_port,
    authentication: SSHAuthentication(
        username: "my_username",
        method: .password(.init("my_password")),
        hostKeyValidation: .acceptAll()
    )
)

try await connection.start()

Once connected, you can start executing concrete SSH operations on child communication channels. As SSH Client means to be a high level interface, you do not directly interact with them. Instead you use interfaces dedicated to your use case.

  • SSH commands
let response = try await connection.execute("echo Hello\n")
// Handle response

for try await chunk in connection.stream("echo World\n") {
    // Handle chunk
}
  • SSH shell
let shell = try await connection.requestShell()
for try await chunk in shell.data {
    // Handle chunk
}
  • SFTP client
let sftpClient = try await connection.requestSFTPClient()

// directories
try await sftpClient.createDirectory(at: "./new")
try await sftpClient.removeDirectory(at: "./new")

// files
let file = try await client.openFile(at: "./new/file.txt", flags: .create)
try await file.write("Hello World!".data(using: .utf8)!)
try await file.close()

// and more

You keep track of the connection state, using the dedicated stateUpdateHandler property:

connection.stateUpdateHandle = { state in
    switch state {
    case .idle, .failed:
        // Handle disconnection
    case .ready:
        // Handle connection start
    }
}

As SSHConnection represents the overall SSH connection, if it ends, all the SSH operations or clients linked to it will end accordingly.

Beta version

Consider the 0.1 version as a beta version. From patch to patch, the project API can change a lot.

License

Swift SSH Client is available under the MIT license. See the LICENSE.txt file for more info.

swift-ssh-client's People

Contributors

gaetanzanella 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.