在Swift项目中使用SSH登录路由器
使用三方库NMSSH连接
pod 'NMSSH'
在xxx-Bridging-Header
文件中导入头文件
// NMSSH
#import <NMSSH/NMSSH.h>
在项目中使用方法
let session = NMSSHSession.connect(toHost: "10.0.0.254", withUsername: "root")
if session.isConnected {
print("Successfully created a new session")
}
session.authenticate(byPassword: "password")
if session.isAuthorized {
print("Successfully authorized")
let response = session.channel.execute("df -h", error: nil, timeout: 3)
print("---res--\(response)")
}
session.disconnect()
网友评论