Swiftpack.co - gaetanzanella/swift-ssh-client as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by gaetanzanella.
gaetanzanella/swift-ssh-client 0.1.4
High-level SSH client interfaces using SwiftNIO SSH
⭐️ 13
🕓 32 weeks ago
iOS macOS
.package(url: "https://github.com/gaetanzanella/swift-ssh-client.git", from: "0.1.4")

Swift SSH Client

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


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.


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


Stars: 13
Last commit: 6 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

32 weeks ago


  • Queue configuration public API

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics