我一直在努力,並試圖讓蘋果SimpleFTPSample爲我工作,但我不能。下面是我一直使用的代碼:爲什麼我無法看到SimpleFTPSample代碼爲我工作?
BOOL success;
CFWriteStreamRef ftpStream;
NSLog(@"Hello");
// assert(self.networkStream == nil); // don't tap send twice in a row!
// assert(self.fileStream == nil); // ditto
// First get and check the URL.
url = [NSURL URLWithString:@hostname];
success = (url != nil);
NSLog(@"After first success");
if (success) {
NSLog(@"In the success if");
// 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.
if(fileName) NSLog(@"Filename.");
if(url) NSLog(@"url");
url = [NSMakeCollectable(
CFURLCreateCopyAppendingPathComponent(NULL, (CFURLRef) url,
//(CFStringRef) [fileName lastPathComponent],
(CFStringRef)pngPath,
false)
) autorelease];
[url retain];
NSLog(@"After url=");
success = (url != nil);
assert(success);
NSLog(@"End of success if");
}
// If the URL is bogus, let the user know. Otherwise kick off the connection.
if (! success) {
NSLog(@"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:pngPath];
assert(self.fileStream != nil);
[self.fileStream open];
// Open a CFFTPStream for the URL.
ftpStream = CFWriteStreamCreateWithFTPURL(NULL, (CFURLRef) url);
if(!ftpStream) NSLog(@"ftpStream is null");
assert(ftpStream != NULL);
self.networkStream = (NSOutputStream *) ftpStream;
#pragma unused (success) //Adding this to appease the static analyzer.
success = [self.networkStream setProperty:@"JEFF" forKey:(id)kCFStreamPropertyFTPUserName];
assert(success);
success = [self.networkStream setProperty:@"jeffrack" forKey:(id)kCFStreamPropertyFTPPassword];
assert(success);
self.networkStream.delegate = self;
[self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];
// Have to release ftpStream to balance out the create. self.networkStream
// has retained this for our persistent use.
CFRelease(ftpStream);
// Tell the UI we're sending.
[self _sendDidStart];
}
}
在這個例子中,主機名是FTP服務器的IP地址。我一直得到的問題是,在我的NSLog(@"After url=")
網址一直爲空,我無法弄清楚爲什麼它一直被創建爲空。另外,pngPath是我試圖上傳的圖像所在的NSString。有沒有人知道編輯簡單樣本的簡單方法,因爲我已經在這裏工作了幾個星期,並且無法使其工作。
此外,我無法找到他們的API上的任何東西,使其以被動模式發送,有沒有人知道我該如何做這項工作呢?謝謝!