SSH and SCP connections

Hi,

I'm looking to use SwiftNIO to make a simple SSH connection with a device (requires giving the IP address, username, and password) to make simple BASH commands and use SCP to move files on and off the device. I've been looking through the GitHub page but I'm a bit lost in this epic tool. Is there anywhere that demos how to make such a simple connection along with; hopefully, how to do the actions. Thank you.

1 Like

As you've discovered, swift-nio-ssh is a little intimidating. This is because, like SwiftNIO in general, it isn't a high-level abstraction but a low-level implementation tool. It expects that you know roughly how SSH works at the wire protocol, and gives you tools to work with that wire format, but it's far from the level of abstraction that something like libssh would provide.

Before I go down the road of explaining how to use this tool directly, I might first suggest investigating whether you can find a higher-level wrapper. I know that @Joannis_Orlandos has worked on Citadel: I'm not sure what the current state of that project is, but it may be easier to work with than with swift-nio-ssh directly.

If that turns out to be unacceptable for your use-case, the NIOSSHClient example is the best place to start looking. This is not a really great example for perfectly what you need because it's trying to demonstrate a number of features, but if you follow the code path for executing functions you should be able to begin to see the basics.

3 Likes

For an example of executing a command remotely you could also have a look at: GitHub - orobio/SshClient

It's far from perfect and there are some things I'd like to change, but as an example it could be useful.

1 Like