2012-10-06 4 views
0

iOS simpleFTP 예제를 가이드로 사용하여 파일을 내 ftp 서버 (http://developer.apple.com/library/ios/#samplecode/SimpleFTPSample/Listings/Read_Me_About_SimpleFTPSample_txt.html)에 업로드하고 있습니다. 파일에 로컬로 데이터가 들어 있지만 내 응용 프로그램이 내 FTP 서버에 파일을 업로드 한 후 비어있는 (0 바이트) 파일을 표시합니다. 아무도 내 코드에서 왜 이런 일이 일어나고 있는지 확인할 수 있습니까? 여기 코드는 다음과 같습니다iOS objective csv 파일을 FTP 서버에 업로드

NSString *resultLine = [NSString stringWithFormat:@"%@,%@,%@", 
          aField.text, bField.text, cField.text]; 

    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

    NSString *csvFileName = [NSString stringWithFormat:@"%@.csv",aField.text]; 

    NSString *reportsCSV = [docPath stringByAppendingPathComponent:csvFileName]; 

    if([[NSFileManager defaultManager] fileExistsAtPath:reportsCSV]) 
    { 
     [[NSFileManager defaultManager] removeItemAtPath:reportsCSV error:NULL]; 
    } else{ 
     [[NSFileManager defaultManager] createFileAtPath:reportsCSV contents:nil attributes:nil]; 
    } 

    NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:reportsCSV]; 
    [fileHandle seekToEndOfFile]; 
    [fileHandle writeData:[resultLine dataUsingEncoding:NSUTF8StringEncoding]]; 
    [fileHandle closeFile]; 

    if([[NSFileManager defaultManager] fileExistsAtPath:reportsCSV]) 
    { 
     NSLog(@"File report type CSV: %@", reportsCSV); 
     if (! self.isSending) { 
      [self startSend:reportsCSV]; 
     } 

    } 

startSend 방법 : 나는 파일 업로드 클래스가

- (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:@"ftp.fooftp.com"]; 
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.sendingLabel.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); 


     success = [self.networkStream setProperty:@"user" forKey:(id)kCFStreamPropertyFTPUserName]; 
     assert(success); 
     success = [self.networkStream setProperty:@"pass" forKey:(id)kCFStreamPropertyFTPPassword]; 
     assert(success); 

    self.networkStream.delegate = self; 
    [self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 
    [self.networkStream open]; 

    // Tell the UI we're sending. 

    [self sendDidStart]; 
    } 
} 
+0

위 프레임 워크를 사용하려면 기존 프레임 워크를 사용하는 것이 좋습니다. 인터넷 요청 : RestKit, AFNetworking 등 – Nekto

+0

NSUrlConnection도 사용할 수 있습니다. 또한 FTP도 알고 있습니다. 모두 매우 높은 수준. –

답변

0

내가하지만 TXT 파일 및 이미지 파일과 같은 상황에있어 ... 이 클래스는 뷰 컨트롤러 예제를 기반으로하고 있으며 같은 프로젝트에있는 샘플의 뷰 컨트롤러가 있으며 업로드 된 파일은 비어 있습니다 (0 바이트).하지만 뷰 컨트롤러에서는 발생하지 않습니다. 정확하게 ...

관련 문제