I want to implement a "today extension" and send ssh commands with a button from there.
Sometimes this button is pressed multiple times and there is a chance that the previous connection is not closed yet.
Is there any way to "intercept" the previous command and send it there? I have already tried following code but this did not work either:
if (command.connected && command.authenticated){
command.execute(command) { (command, result: String?, error) in
if let result = result {
// ...
} else {
// connect normally
}
Here is my file:
import UIKit
import NotificationCenter
import SwiftSH
class TodayViewController: UIViewController, NCWidgetProviding {
var command: Command!
@IBOutlet var button1: UIButton!
// ...
override func viewDidLoad() {
super.viewDidLoad()
self.command = Command(host: "111.222.3.444", port: 22)
// ...
}
@IBAction func button1Pressed(sender: UIButton){
performCommand("pwd")
}
func performCommand(_ cmd: String) {
print("send Command " + cmd)
self.command
.connect()
.authenticate(.byPassword(username: "user", password: "pass"))
.execute(cmd) { (cmd, result: String?, error) in
if let result = result {
//...
} else {
//...
}
}
}
}
Hi,
I want to implement a "today extension" and send ssh commands with a button from there.
Sometimes this button is pressed multiple times and there is a chance that the previous connection is not closed yet.
Is there any way to "intercept" the previous command and send it there? I have already tried following code but this did not work either:
Here is my file: