-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathindex.html
355 lines (264 loc) · 9.47 KB
/
index.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="description" content="Blackraccoon : IOS FTP Client Code" />
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
<title>Blackraccoon</title>
</head>
<body>
<!-- HEADER -->
<div id="header_wrap" class="outer">
<header class="inner">
<a id="forkme_banner" href="https://github.com/lloydsargent/BlackRaccoon">View on GitHub</a>
<h1 id="project_title">Blackraccoon</h1>
<h2 id="project_tagline">IOS FTP Client Code</h2>
<section id="downloads">
<a class="zip_download_link" href="https://github.com/lloydsargent/BlackRaccoon/zipball/master">Download this project as a .zip file</a>
<a class="tar_download_link" href="https://github.com/lloydsargent/BlackRaccoon/tarball/master">Download this project as a tar.gz file</a>
</section>
</header>
</div>
<!-- MAIN CONTENT -->
<div id="main_content_wrap" class="outer">
<section id="main_content" class="inner">
<h2>General Notes</h2>
<p>BlackRaccoon is a collection of routines used to act as an FTP client. It was specifically
designed to work correctly under ARC and to "fix" a leak in the listing of directories.</p>
<p>With BlackRaccoon you can:</p>
<ul>
<li> Download a file</li>
<li> Upload a file</li>
<li> Delete a file</li>
<li> Create a directory</li>
<li> Delete a directory</li>
<li> List a directory</li>
</ul><p>A function to queue requests has been left in the code, but has not been tested. As this
is not a normal FTP function, the user should assume it is deprecated and will be removed
from future releases.</p>
<p>As with WhiteRaccoon, the user needs to assure that the <strong>CFNetwork</strong> framework has been
added to the project.</p>
<h3>License</h3>
<p>License is the MIT License. Basically means you can use as you wish just keep the copyright
notice in the source code.</p>
<h3>Differences Between WhiteRaccoon and BlackRaccoon</h3>
<p>BlackRaccoon works correctly with ARC. A lot of time and effort went in to assure there
were no leaks.</p>
<p>BlackRaccoon, unlike WhiteRaccoon, breaks up files by objects. This is for this author's
convenience. If you wish to combine them again, feel free.</p>
<p>BlackRaccoon has been tested with an unencrypted FTP server. However, it has NOT been
tested with all manner of usernames and passwords.</p>
<p>Added helper function <em>initWithDelegate</em> to major classes.</p>
<p>All FTP operations will either call RequestCompleted for a positive response or
RequestFailed if it is a negative response.</p>
<h3>Usage</h3>
<p>The following code assumes the following:</p>
<pre><code>@interface myclass : NSObject <BRRequestDelegate>
{
BRRequestCreateDirectory *createDir;
BRRequestDelete * deleteDir;
BRRequestListDirectory *listDir;
BRRequestDownload *downloadFile;
BRRequestUpload *uploadFile;
BRRequestDelete *deleteFile;
}
</code></pre>
<h4>Create Directory</h4>
<pre><code>- (IBAction) createDirectory:(id)sender
{
createDir = [BRRequestCreateDirectory initWithDelegate: self];
createDir.path = @"/home/test/yourdirectory/";
createDir.hostname = @"192.168.1.5";
createDir.username = @"yourusername";
createDir.password = @"yourpassword";
//we start the request
[createDir start];
}
</code></pre>
<h4>Delete Directory</h4>
<pre><code>- (IBAction) deleteDirectory:(id)sender
{
deleteDir = [BRRequestDelete initWithDelegate: self];
deleteDir.path = @"/home/test/yourdirectory/";
deleteDir.hostname = @"192.168.1.5";
deleteDir.username = @"yourusername";
deleteDir.password = @"yourpassword";
//we start the request
[deleteDir start];
}
</code></pre>
<h4>List Directory</h4>
<pre><code>- (IBAction) listDirectory:(id)sender
{
listDir = [BRRequestListDirectory initWithDelegate: self];
listDir.path = @"/home/test/yourdirectory/";
listDir.hostname = @"192.168.1.5";
listDir.username = @"yourusername";
listDir.password = @"yourpassword";
[listDir start];
}
</code></pre>
<h4>Download a File</h4>
<pre><code>- (IBAction) downloadFile :(id)sender
{
downloadFile = [BRRequestDownload initWithDelegate: self];
downloadFile.path = @"/home/test/yourfile";
//for anonymous login just leave the username and password nil
downloadFile.hostname = @"192.168.1.5";
downloadFile.username = @"yourusername";
downloadFile.password = @"yourpassword";
//we start the request
[downloadFile start];
}
</code></pre>
<h4>Upload a File</h4>
<pre><code>- (IBAction) uploadFile :(id)sender
{
//----- get the file to upload as an NSData object
NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filepath = [NSString stringWithFormat: @"%@/%@", applicationDocumentsDir, @"image.jpg"];
NSData *dataToUpload = [NSData dataWithContentsOfFile: filepath];
uploadFile = [BRRequestUpload initWithDelegate: self];
uploadFile.sentData = dataToUpload;
uploadFile.path = @"/home/test/yourfile";
//for anonymous login just leave the username and password nil
uploadFile.hostname = @"192.168.1.5";
uploadFile.username = @"yourusername";
uploadFile.password = @"yourpassword";
//we start the request
[uploadFile start];
}
</code></pre>
<h4>Delete a File</h4>
<pre><code>- (IBAction) deleteFile: (id) sender
{
deleteFile = [BRRequestDelete initWithDelegate: self];
deleteFile.path = @"/home/test/yourfile";
//----- for anonymous login just leave the username and password nil
deleteFile.hostname = @"192.168.1.5";
deleteFile.username = @"yourusername";
deleteFile.password = @"yourpassword";
//----- we start the request
[deleteFile start];
}
</code></pre>
<h4>Delegate callback to determine if something should be overwritten</h4>
<pre><code>-(BOOL) shouldOverwriteFileWithRequest: (BRRequest *) request
{
//----- set this as appropriate if you want the file to be overwritten
if (request == uploadFile)
{
//----- if uploading a file, we set it to YES
return YES;
}
//----- anything else (directories, etc) we set to NO
return NO;
}
</code></pre>
<h4>Request Completed</h4>
<pre><code>-(void) requestCompleted: (BRRequest *) request
{
//----- handle Create Directory
if (request == createDir)
{
NSLog(@"%@ completed!", request);
createDir = nil;
}
//----- handle Delete Directory
if (request == deleteDir)
{
NSLog(@"%@ completed!", request);
deleteDir = nil;
}
//----- handle List Directory
if (request == listDir)
{
//----- called after 'request' is completed successfully
NSLog(@"%@ completed!", request);
//----- we print each of the file names
for (NSDictionary *file in listDir.filesInfo)
{
NSLog(@"%@", [file objectForKey: (id) kCFFTPResourceName]);
}
logview.text = [NSString stringWithFormat: @"%@\n", logview.text];
[logview scrollRangeToVisible: NSMakeRange([logview.text length] - 1, 1)];
listDir = nil;
}
//----- handle Download File
if (request == downloadFile)
{
//called after 'request' is completed successfully
NSLog(@"%@ completed!", request);
NSData *data = downloadFile.receivedData;
//----- save the NSData as a file object
NSError *error;
NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filepath = [NSString stringWithFormat: @"%@/%@", applicationDocumentsDir, @"image.jpg"];
[data writeToFile: filepath options: NSDataWritingFileProtectionNone error: &error];
downloadFile = nil;
}
if (request == uploadFile)
{
NSLog(@"%@ completed!", request);
uploadFile = nil;
}
if (request == deleteFile)
{
NSLog(@"%@ completed!", request);
deleteFile = nil;
}
}
</code></pre>
<h4>Request Failed</h4>
<pre><code>-(void) requestFailed:(BRRequest *) request
{
//----- handle Create Directory
if (request == createDir)
{
NSLog(@"%@", request.error.message);
createDir = nil;
}
//----- handle Delete Directory
if (request == deleteDir)
{
NSLog(@"%@", request.error.message);
deleteDir = nil;
}
//----- handle List Directory
if (request == listDir)
{
NSLog(@"%@", request.error.message);
listDir = nil;
}
//----- handle Download a File
if (request == downloadFile)
{
NSLog(@"%@", request.error.message);
downloadFile = nil;
}
//----- handle Upload a File
if (request == uploadFile)
{
NSLog(@"%@", request.error.message);
uploadFile = nil;
}
//----- handle Delete a File
if (request == deleteFile)
{
NSLog(@"%@", request.error.message);
deleteFile = nil;
}
}
</code></pre>
</section>
</div>
<!-- FOOTER -->
<div id="footer_wrap" class="outer">
<footer class="inner">
<p class="copyright">Blackraccoon maintained by <a href="https://github.com/lloydsargent">lloydsargent</a></p>
<p>Published with <a href="http://pages.github.com">GitHub Pages</a></p>
</footer>
</div>
</body>
</html>