SwiftSH
一个封装了 libssh2 的 Swift SSH 框架。
功能
- 线程安全
- SSH shell
- SSH 命令
- SCP
- SFTP
- 测试
- 文档
📦 安装
CocoaPods
CocoaPods 是 Swift 和 Objective-C 的 Cocoa 项目的依赖管理器。它有超过 10000 个库,并且可以帮助您优雅地扩展项目。
将其添加到您的 Podfile
use_frameworks!
pod 'SwiftSH'
Carthage
Carthage 构建您的依赖,并提供二进制框架,但您对项目和设置拥有完全的控制。
将其添加到您的 Cartfile
github "Frugghi/SwiftSH"
📖 文档
API 文档在这里可以获得 here。
💻 用法
导入框架
import SwiftSH
执行 SSH 命令
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)")
}
}
打开 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 和 Libssh2 二进制包
SwiftSH 包含使用 此脚本 所生成的、预编译的 Libssh2 和 OpenSSL 的二进制包。出于安全原因,强烈建议您重新编译库并替换二进制包。
📄 许可 
SwiftSH 采用了 MIT 许可证发布。有关详细信息,请参阅 LICENSE。