This repository was archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathAppDelegate.swift
78 lines (61 loc) · 2.18 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// AppDelegate.swift
// Demo
//
// Created by Constantine Fry on 17/05/15.
// Copyright (c) 2015 Constantine Fry. All rights reserved.
//
import UIKit
import RebekkaTouch
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var session: Session!
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
var configuration = SessionConfiguration()
configuration.host = "ftp://speedtest.tele2.net"
self.session = Session(configuration: configuration)
testList()
//testDownload()
//testUpload()
//testCreate()
return true
}
func testList() {
self.session.list("/") {
(resources, error) -> Void in
print("List directory with result:\n\(resources!), error: \(error!)\n\n")
}
}
func testUpload() {
if let URL = Bundle.main.url(forResource: "TestUpload", withExtension: "png") {
let path = "/upload/\(UUID().uuidString).png"
self.session.upload(URL, path: path) {
(result, error) -> Void in
print("Upload file with result:\n\(result), error: \(error!)\n\n")
}
}
}
func testDownload() {
self.session.download("/1MB.zip") {
(fileURL, error) -> Void in
print("Download file with result:\n\(fileURL!), error: \(error!)\n\n")
if let fileURL = fileURL {
do {
try FileManager.default.removeItem(at: fileURL)
} catch let error as NSError {
print("Error: \(error)")
}
}
}
}
func testCreate() {
let name = UUID().uuidString
self.session.createDirectory("/upload/\(name)") {
(result, error) -> Void in
print("Create directory with result:\n\(result), error: \(error!)")
}
}
}