NMSSH does not connect with SWIFT

2019-05-24 11:07发布

问题:

I just tried to use NMSSH for the first time but it simply does not connect for me

import UIKit
import NMSSH

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let session = NMSSHSession(host: "11.111.11.11", andUsername: "vnc")
        if session.connected == true{
            session.authenticateByPassword("1234")
            if session.authorized == true {
                print("works")
            }
        }

    }


}

回答1:

did forget the session.connect() to start the connection

let session = NMSSHSession(host: "11.111.11.11", andUsername: "inc")
        session.connect()
        if session.connected == true{
            session.authenticateByPassword("1234")
            if session.authorized == true {
                print("works")
            }
        }