나는 Apples 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=")
에서 url이 계속 null이되고 null로 생성되는 이유를 알 수 없다는 것입니다. 또한, pngPath는 내가 업로드하려고하는 이미지가있는 NSString입니다. 아무도 간단한 샘플을 편집하는 간단한 방법을 알고 있습니까? 왜냐하면 저는 2 주 동안이 작업을 해왔으므로 제대로 작동하지 않습니다.
또한 API에서 수동 모드로 전송할 수있는 항목을 찾을 수 없으며 누구나 내가 그 작업을 수행 할 수있는 방법을 알고 있습니까? 감사!