How to programmatically use SFTP in a SwiftUI macOS app?

Is there an easy way to programmatically use SFTP in my SwiftUI macOS app? In my macOS app I need to do things like:

  • upload local files to a remote server
  • create a directory on a remote server
  • download files from a remote server
  • delete files on a remote server

I have been researching this subject for awhile and people are recommending things like SwiftNIO and libssh. But those seem pretty low level and kind of a headache to use.

Another option is to use the sftp CLI command via the foundation Process object. I like this option and am considering experimenting with this, but it seems like a hack. Will this work on all macOS computers?

Is there an easy way to import and use a C/C++ SFTP library in my SwiftUI macOS app?

At this point in my research of this subject I feel like I have to go deep down some rabbit hole in order to pull of some SFTP functionality. But I'm wondering, is there some easy way to do this that I'm missing?

Another option is to use the sftp CLI command via the foundation Process object. I like this option and am considering experimenting with this, but it seems like a hack.

How much of a "hack" this turns into really depends on how you end up needing to interact with the tool If you can structure your interactions with the tool such that you're simply sending the command and getting a result, then it can actually work reasonably well. Indeed, there are a number of command line tools that effectively operate as API and have even been designed to facilitate that functionality (notably, hdiutil and disk image mounting). ssh is another example of this- many applications intentionally use the ssh command line tool instead of integrating with a library because using the command line allows them to rely more on the users existing security configuration instead of having to duplicate that functionality.

However, if you'll end up need to drive the tool interactively, that can be pretty painful. Similarly, things like progress and status updates on long running operations can be quite painful, depending on exactly how the tool works.

Will this work on all macOS computers?

The word "all" is very tricky when it comes to macOS, as the system is so configurable that almost every generalizations has exceptions. What I will say is that I don't think it will be "accidentally" missing- that is, it's going to be there and should "work" unless it was specifically removed/disabled.

Is there an easy way to import and use a C/C++ SFTP library in my SwiftUI macOS app?

That really depends on the library. The issue(s) here tend to not be with the language itself, but with whatever complicated build environment the library has created for itself.

At this point in my research of this subject I feel like I have to go deep down some rabbit hole in order to pull of some SFTP functionality. But I'm wondering, is there some easy way to do this that I'm missing?

Not that I'm aware of.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

How to programmatically use SFTP in a SwiftUI macOS app?
 
 
Q