-
Notifications
You must be signed in to change notification settings - Fork 4
/
ACFTPHelper.m
40 lines (33 loc) · 1.18 KB
/
ACFTPHelper.m
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
//
// FTPHelper.m
// OnSong
//
// Created by Jason Kichline on 3/24/11.
// Copyright 2011 andCulture. All rights reserved.
//
#import "ACFTPHelper.h"
@implementation ACFTPHelper
+(NSURL*)urlByRemovingCredentials:(NSURL*)input {
NSString* str = [input absoluteString];
NSRange from = [str rangeOfString:@"://"];
NSRange to = [str rangeOfString:@"@"];
str = [NSString stringWithFormat:@"%@%@", [str substringToIndex:from.location + from.length], [str substringFromIndex:to.location + to.length]];
return [NSURL URLWithString:str];
}
+(NSURL*)urlByAddingCredentials:(NSURL*)input username:(NSString*)username password:(NSString*)password {
NSString* str = [input absoluteString];
// If we already have credentials, send it out
if(username == nil || [str rangeOfString:@"@"].length > 0) {
return input;
}
// Insert the username/password
NSMutableString* o = [NSMutableString stringWithString:str];
NSRange at = [str rangeOfString:@"://"];
NSString* pwd = @"";
if(password != nil) {
pwd = [NSString stringWithFormat:@":%@", password];
}
[o insertString:[NSString stringWithFormat:@"%@%@@", username, pwd] atIndex:at.location + at.length];
return [NSURL URLWithString:o];
}
@end