 
                     PHImageManager.defaultManager().requestImageDataForAsset(asset, options: myOptions, resultHandler: {
                         imageData, dataUTI, orientation, info in
-                        let file = self.uploadPhoto(sftpSession!, imageData: imageData!, info: info!, index: counter, totalNumber: assets.count, creationDate: asset.creationDate!)
+                        // swiftlint:disable:next force_cast
+                        let url = (info! as NSDictionary).valueForKey("PHImageFileURLKey") as! NSURL
+
+                        let file = self.uploadFile(sftpSession!, fileData: imageData!, originalURL: url, index: counter, totalNumber: photoAssets.count + videoAssets.count, creationDate: asset.creationDate!)
 
                         if file != nil {
                             filesToBeKept.insert(file!)
                         }
                     })
+                }
+
+                for asset in videoAssets {
+                    counter += 1
+
+                    // Allow since this always comes from PHAsset.fetchAssetsWithMediaType
+                    // swiftlint:disable:next force_cast
+                    let asset = asset as! PHAsset
+
+                    // This request must be synchronous otherwise the resultHandler ends up back on the main thread.
+                    let options = PHVideoRequestOptions()
+                    options.networkAccessAllowed = true
+
+                    let semaphore = dispatch_semaphore_create(0)
+
+                    PHImageManager.defaultManager().requestAVAssetForVideo(asset, options: options, resultHandler: {
+                        videoAsset, audioMix, info in
+                        let urlAsset = videoAsset as? AVURLAsset
+                        if urlAsset != nil {
+                            let url = urlAsset!.URL
+                            NSLog("Video asset URL is " + url.description)
+
+                            let videoData = NSData(contentsOfURL: url)!
+
+                            let file = self.uploadFile(sftpSession!, fileData: videoData, originalURL: url, index: counter, totalNumber: photoAssets.count + videoAssets.count, creationDate: asset.creationDate!)
+
+                            if file != nil {
+                                filesToBeKept.insert(file!)
+                            }
+                        }
+
+                        dispatch_semaphore_signal(semaphore)
+                    })
+
+                    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
                 }
 
                 self.updateStatus("Uploading complete successfully.")

        }
    }

    func getUniqueFilename(date: NSDate, imageData: NSData) -> String {
        let dateFormatter = NSDateFormatter()
        let enUSPosixLocale = NSLocale(localeIdentifier: "en_US_POSIX")
        dateFormatter.locale = enUSPosixLocale
        dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
        let formattedDate = dateFormatter.stringFromDate(date)

        let hash = imageData.crc32()

        return formattedDate + "_" + hash!.toHexString()
    }

    }

    // swiftlint:disable:next function_parameter_count
    func uploadFile(sftpSession: NMSFTP, fileData: NSData, originalURL: NSURL, index: Int, totalNumber: Int, creationDate: NSDate) -> String? {
        let uniqueFilename = getUniqueFilename(creationDate, fileData: fileData)

        let originalFilePathString = originalURL.absoluteString
        NSLog("Original file path is " + originalFilePathString)

        var originalFileExtension = originalURL.pathExtension
        originalFileExtension = (originalFileExtension == nil) ? "" : "." + originalFileExtension!
        NSLog("Original file extension is " + originalFileExtension!)

        let finalFileName = uniqueFilename + originalFileExtension!
        let finalFilePath =  self.remoteDir.text! + "/" + finalFileName
        let tempFilePath = self.remoteDir.text! + "/.tmp" + originalFileExtension!
        NSLog("Final file path is " + finalFilePath)
        NSLog("Temp file path is " + tempFilePath)

        let localFileLength = fileData.length

        if sftpSession.fileExistsAtPath(finalFilePath) &&
            sftpSession.infoForFileAtPath(finalFilePath).fileSize == localFileLength &&
