I'm trying to establish an SFTP connection to transfer files between my app and a remote server. Is it possible to do this using Swift? If so, can you provide any guidance on how to implement this functionality? I would also like to know how to download and upload files using SFTP.
Establishing SFTP Connection and File Transfer in Swift
Have a look at callable cURL as a potential option. https://curl.se
The command converter tool might be helpful in stitching together the code, too. https://curlconverter.com/swift/
More common would be HTTPS transfers via REST (and not file transfers via ssh as sftp does); whether using Alamofire or otherwise.
Depending on your deployment environments, also make sure TCP 22 is going to be open, too. Some environments block that sort of thing.
There is no Apple API for SFTP.
If you’re on macOS, it might be able to meet your goals by running the sftp
command-line tool using Process
. Otherwise, you’ll need a third-party SFTP library.
One place to start might be SwiftNIO SSH. That doesn’t do SFTP per se, but it does all the heavy lifting of SSH and you might be able to run from there.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"