Neph
Neph

Reputation: 2001

FTP with Swift 4/5 (with/without extra framework)

First of all: I know about the security concerns regarding ftp, so please no discussion about this here - ftp has to be used.

My app has to log into a server with ftp (with username/password), search for and download a file, delete it from the server, then upload an edited version.

I've been searching for tutorials on how to even get a connection to a server via ftp but all I found were Apple's documentation from 2012 here and their documentation about the different functions here (and a bunch of weird "Swift FTP" biking videos on youtube...). Every other example I found (usually <2015) uses some additional framework or library but there don't seem to be any proper tutorial for Swift 5 or even Swift 4.

Is it even still possible to use FTP with Swift 5 (is it still supported?) and if so, how? Or is there simply no point trying to get any of Apple's stuff to work and better to just use an extra framework like FileProvider?

Upvotes: 3

Views: 4085

Answers (1)

Neph
Neph

Reputation: 2001

At first I was using FileProvider, unfortunately the library is pretty buggy currently, with functions being called twice (which you can kind of prevent by using a "firstTimeCalled" bool check) and if the server's slow(-ish), you also might not get e.g. the full list of files in a directory because FileProvider stops receiving answers before the server's actually done.

I haven't found any other FTP libraries for Swift that work (and are still supported), so now I'm using BlueSocket (which is able to open sockets, send commands to the server and receive commands from it) and built my own small library that can send/receive,... files (using the FTP codes) around it.

Upvotes: 1

Related Questions