我一直在努力,并试图让苹果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上的任何东西,使其以被动模式发送,有没有人知道我该如何做这项工作呢?谢谢!