NSURLSession Upload File To Server Swift
<p>I'm creating a Internet Speed testing app and can't seem to get it right to upload the zip file to the ftp server. It is an open server. I want to be able to upload the file and show the progress.</p>

<p>The <code>func URLSession(session: NSURLSession, task: NSURLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64)</code> isn't working.</p>

<pre><code>import UIKit
import Foundation

class Upload: UIViewController, NSURLSessionTaskDelegate, NSURLSessionDataDelegate, NSURLSessionDelegate {

    let url: NSURL = NSURL(string: "ftp://speedtest.tele2.net/upload")!
    let path = NSBundle.mainBundle().pathForResource("2MB", ofType: "zip")

    func Test() {
        let data: NSData = NSData(contentsOfFile: path!)!

        let request: NSMutableURLRequest = NSMutableURLRequest(URL: url)
        request.HTTPMethod = "POST"
        request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData
        request.timeoutInterval = 10.0
        request.HTTPBody = data

        let session: NSURLSession = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(), delegate: self, delegateQueue: NSOperationQueue.mainQueue())
        let task: NSURLSessionUploadTask = session.uploadTaskWithRequest(request, fromData: data)

        task.resume()
    }

    func URLSession(session: NSURLSession, task: NSURLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
        print("\(totalBytesSent)/\(totalBytesExpectedToSend)")
    }

    func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) {
        print(error)
    }

    func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveResponse response: NSURLResponse, completionHandler: (NSURLSessionResponseDisposition) -&gt; Void) {
        completionHandler(NSURLSessionResponseDisposition.Allow)
    }

    func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveData data: NSData) {
        //
    }

}
</code></pre>