Created
August 24, 2012 09:51
-
-
Save amay077/3448448 to your computer and use it in GitHub Desktop.
SimpleFtpSample - Disable Keep-Alive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)startSend:(NSString *)filePath | |
{ | |
BOOL success; | |
NSURL * url; | |
assert(filePath != nil); | |
assert([[NSFileManager defaultManager] fileExistsAtPath:filePath]); | |
assert( [filePath.pathExtension isEqual:@"png"] || [filePath.pathExtension isEqual:@"jpg"] ); | |
assert(self.networkStream == nil); // don't tap send twice in a row! | |
assert(self.fileStream == nil); // ditto | |
// First get and check the URL. | |
url = [[NetworkManager sharedInstance] smartURLForString:self.urlText.text]; | |
success = (url != nil); | |
if (success) { | |
// Add the last part of the file name to the end of the URL to form the final | |
// URL that we're going to put to. | |
url = CFBridgingRelease( | |
CFURLCreateCopyAppendingPathComponent( | |
NULL, (__bridge CFURLRef) url, | |
(__bridge CFStringRef) [filePath lastPathComponent], false) | |
); | |
success = (url != nil); | |
} | |
// If the URL is bogus, let the user know. Otherwise kick off the connection. | |
if ( ! success) { | |
self.statusLabel.text = @"Invalid URL"; | |
} else { | |
// Open a stream for the file we're going to send. We do not open this stream; | |
// NSURLConnection will do it for us. | |
self.fileStream = [NSInputStream inputStreamWithFileAtPath:filePath]; | |
assert(self.fileStream != nil); | |
[self.fileStream open]; | |
// Open a CFFTPStream for the URL. | |
self.networkStream = CFBridgingRelease( | |
CFWriteStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url) | |
); | |
assert(self.networkStream != nil); | |
if ([self.usernameText.text length] != 0) { | |
success = [self.networkStream setProperty:self.usernameText.text | |
forKey:(id)kCFStreamPropertyFTPUserName]; | |
assert(success); | |
success = [self.networkStream setProperty:self.passwordText.text | |
forKey:(id)kCFStreamPropertyFTPPassword]; | |
assert(success); | |
} | |
// Disable Keep-alive | |
[self.networkStream setProperty:(id)kCFBooleanFalse | |
forKey:(id)kCFStreamPropertyFTPAttemptPersistentConnection]; | |
self.networkStream.delegate = self; | |
[self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] | |
forMode:NSDefaultRunLoopMode]; | |
[self.networkStream open]; | |
// Tell the UI we're sending. | |
[self sendDidStart]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://amay077.posterous.com/ftp-keep-alive