SwiftSH icon indicating copy to clipboard operation
SwiftSH copied to clipboard

Invalid example of ssh command

Open nmingotti opened this issue 4 years ago • 3 comments

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 avatar Apr 23 '20 07:04 nmingotti

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)")
           }
       }

nmingotti avatar Apr 24 '20 06:04 nmingotti

@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!

avneet-01 avatar Mar 11 '21 19:03 avneet-01

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

nmingotti avatar Apr 15 '21 19:04 nmingotti