Be sure that you FTP info is correct!!
Once again I find myself with a problem that should have a simple solution, and yet it gave me hard work to solve.
Apple Library (with examples) is in Objective-C and trying to parse the code to Swift, sometimes (more then less) it doesn't work as intended.
Anyway, the problem is simple:
Uploading a file from your computer/iOS device to a FTP Server !
This is actually quite simple due to OSX's GUI for creating users and turning on FTP access. Follow along and marvel at the simplicity of it all. Open 'System preferences' 2. Click on 'Users' 3. Create a new user ( you may create either a specific user or a generic one for many people. You can use FTP to transfer files from your Mac OS X Snow Leopard computer with an FTP server by using the command-line interface (CLI); to use the CLI, open a Terminal, or shell, session. To use a Terminal session, double-click the Terminal icon in the Utilities folder inside the Applications folder. FTP was removed in macOS High Sierra and macOS Mojave, but ftp and ftp server do remain in older versions of Mac OS and Mac OS X system software, even if the ftp server has to be manually activated with launchctl. In some older versions of Mac OS, you can even connect with ftp from the Finder however.
If you compile this you should see a Output similar to this:
- Formerly called Anarchie, Interarchy has enjoyed a long history as a favored Mac OS, and now Mac OS X, FTP client. It is one of the most advanced programs of its kind, offering several features unavailable in other FTP clients, such as integration with the Mac OS X Network Utility, and supports a number of protocols including SFTP.
- Upload to FTP is an action for Automator. It allows you to easily upload files to your FTP server in any Automator workflow. It accepts files/folders and outputs a list of filenames for all the uploaded files. All this happens in the background, so there's no message outputted to the user, if all goes well.
- The Size of the File
- Loop of bytes written
- Total of bytes written
As you can see my file is 876kb and CFWriteStream has a package limit of 131,4kb that it can send and this is why we need to loop the CFWriteStreamWrite func.
As we can also observe it may send smaller packages, but regardless in the end the Bytes Sent must be equal to the file size.
IMPORTANT NOTE:
This code is what I call 'hard hammered', or in other words, a code that just works. Is this the right way to do it? Maybe not. In this case it is not! Using sleep() func is never the right way to do it
Mac Os Ftp Server
Ok, lets start the journey to try to find the right way to do it.
First and foremost, the previous code is compiled by Swift 1.2
Descargar autotune 2020. With some *Googling* I fount out that we need to create a 'Client' and 'Schedule a RunLoop' which is using the correspondent functions:
CFWriteStreamSetClient()
CFWriteStreamScheduleWithRunLoop()
If we study the CFWriteStreamSetClient() function we see that it requires 4 parameters,
func CFWriteStreamSetClient(stream: CFWriteStream!, streamEvents: CFOptionFlags, clientCB: CFWriteStreamClientCallBack, clientContext:UnsafeMutablePointer) -> Boolean
One of which is a callback function, the problem is that in Swift 1.2 you cannot set a pointer function into another function.
Info link
But then in the same link but another post it is explained a workaround.
Lets test it:
Well no luck because the app will be in a infinite loop and the output is this:
But wait…
Linux Ftp Upload
You can pass any Swift function, method, or closure as a @convention(c) function type â€' but only if that closure conforms to C conventions… e.g. it can't capture state from its surrounding scope.
Output:
…
Conclusion:
Well the only thing I can conclude is that Swift is evolving and it can give us hard times.Mac Ftp Free
Could we use other methods to solve this? yes we could, use objective-c code with Swift and invoke the methods in objective-c. Would it be fun this way? I think not.For me I am trying to abstract the most I can from objective-c, I want to learn Swift the most I can, because I see that in the future objective-c will disappear and Swift will prevail.
Mac Os Ftp Client
And after this we just need to wait for Swift 2.0 to came out of beta and till them just use 'hard hammered' code.
Osx Ftp Client
Have fun and happing coding.
Feedback will be appreciated.