Frugghi / SwiftSH

A Swift SSH framework that wraps libssh2.
MIT License
194 stars 71 forks source link

Invalid example of ssh command #33

Open nmingotti opened 4 years ago

nmingotti commented 4 years ago

Hi, I am very new to iPhone programming, the first and most useful thing I may need to do with my phone is exactly to check server statues. So, I would really like to be able to send a command to a remote server and get the STDOUT,STDERR and exitcode.

In the example provided for 'Execute ssh command' I don't understand where the command for the server really is. Suppose I want to run a simple ls -la, it is not clear at all to me where to write ls -la. I tried to guess it without luck. Any help would be very much appreciated.

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)")
           }
       }
nmingotti commented 4 years ago

Here is how i would write it, to make it more understandable:

let command = Command(host: "localhost", port: 22)
let cmd = "ls -la ; uptime"
// ...
command.connect()
       .authenticate(.byPassword(username: "username", password: "password"))
       .execute(cmd) { (cmd, result: String?, error) in
           if let result = result {
               print("\(result)")
           } else {
               print("ERROR: \(error)")
           }
       }
avneet-01 commented 3 years ago

@nmingotti Is this library used with Objective-C or Swift? Because after installing the Podfile, when I tried importing it in my Swift ViewController, I got the error "Could not build Objective-C Module 'SwiftSH'". Please let me know how to use this library? Thanks in advance!

nmingotti commented 3 years ago

hi @avneet-01 , it is swift. it is several month i don't do phone dev. i can't help sorry.