1

I am using the following code for load list from any ftp server:

    self.networkStream = CFBridgingRelease(
        CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)
    );

    assert(self.networkStream != nil);
    //[self.networkStream setProperty:@"ANONYMOUS" forKey:(id)kCFStreamPropertyFTPUserName];
    //[self.networkStream setProperty:@"abc" forKey:(id)kCFStreamPropertyFTPPassword];
    self.networkStream.delegate = self;
    [self.networkStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
    [self.networkStream open];

Its perfectly loading the list. Then i am showing the list in UITableView. Once the data is loaded i am closing the stream using this code :

if (self.networkStream != nil) {
        [self.networkStream removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
        self.networkStream.delegate = nil;
        [self.networkStream close];
        self.networkStream = nil;
    }

When the user taps on any cell i am trying to load the list of that folder (if its a folder) otherwise i have to download the file from ftp server. For this i am using this code by changing the url :

          self.networkStream = CFBridgingRelease(
                                           CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)

                                           );
   /* [self.networkStream setProperty:( id) kCFBooleanFalse
                             forKey:( NSString *) kCFStreamPropertyFTPAttemptPersistentConnection
     ];
    */
    assert(self.networkStream != nil);
    //[self.networkStream setProperty:@"ANONYMOUS" forKey:(id)kCFStreamPropertyFTPUserName];
    //[self.networkStream setProperty:@"abc" forKey:(id)kCFStreamPropertyFTPPassword];
    self.networkStream.delegate = self;
    [self.networkStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
    [self.networkStream open];

Buts its crashing on this line :

CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)

giving EXC_BAD_ACCESS on this line. I am not able to figure out the reasons. Please Help me out.

Girish
  • 4,692
  • 4
  • 35
  • 55
  • Show us how the url is being initialised and what the url really is. I don't think this has anything to do with rest of the networking code. – zakishaheen Jun 10 '13 at 06:44
  • 1
    To make sure the object is properly type casted, use self.networkStream = (NSInputStream *) CFBridgingRelease(CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)); – Imran Raheem Jun 10 '13 at 07:10
  • url is working fine. I have tried it on every browser (Chrome,firefox and safari). I have tried this use self.networkStream = (NSInputStream *) CFBridgingRelease(CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)); too. but its crashing – user2463198 Jun 10 '13 at 07:20
  • 1
    Browsers have several fall back mechanisms and ability to correct the URL. I need to see where the 'url' variable is coming from. If its EXC_BAD_ACCESS then this pointer is paticularly flawed. – zakishaheen Jun 10 '13 at 08:26
  • yes the issue was with url. i was creating the url ftp:/192.168.1.15:2121/abc/ but the actual url should be "ftp:// address" ftp://192.168.1.15:2121/abc/ "i was missing double slash". Thanks to Imran rahim and debuggerman. – user2463198 Jun 10 '13 at 08:49
  • I met the same problem. Any solution? – Ducky Chen Jul 31 '14 at 08:02

0 Answers0