Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 721883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:55:29+00:00 2026-05-14T05:55:29+00:00

I (apparently) manage to make a ftp connection, but fail to read anything from

  • 0

I (apparently) manage to make a ftp connection, but fail to read anything from it, and with good cause: I don’t reach the reading until the connection has timed out.

Here’s my code:

header:

NSInputStream *iStream;
NSOutputStream *oStream;

implementation:

        NSHost *host = [NSHost hostWithAddress:@"127.0.0.1"];
        [iStream open]; // SOLUTION changes
        [NSStream getStreamsToHost:host port:3333 inputStream:&iStream outputStream:&oStream];

        NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithCapacity:1];
        [settings setObject:(NSString *)NSStreamSocketSecurityLevelTLSv1 forKey:(NSString *)kCFStreamSSLLevel];
        [settings setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
        [settings setObject:@"127.0.0.1" forKey:(NSString *)kCFStreamSSLPeerName];

        /*[iStream retain];   
        [iStream setDelegate:self];
        [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
        CFReadStreamSetProperty((CFReadStreamRef)iStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
        [iStream setProperty:NSStreamSocketSecurityLevelTLSv1 forKey:NSStreamSocketSecurityLevelKey];*/
        //[iStream open]; SOLUTION changes: moved up

For eventhandling I use this, based on http://www.cocoadev.com/index.pl?NSStream:

- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
{
    if (aStream == iStream) {
        [self handleInputStreamEvent:eventCode];
    } else if (aStream == oStream) {
        [self handleOutputStreamEvent:eventCode];
    }
}
- (void)handleInputStreamEvent:(NSStreamEvent)eventCode
{
    switch (eventCode) {
    // SOLUTION changes: new inputstream handler
    case NSStreamEventHasBytesAvailable:
        if(!_data) {
            _data = [[NSMutableData data] retain];
        }
        uint8_t buf[1024];
        unsigned int len = 0;
        len = [(NSInputStream *)iStream read:buf maxLength:1024];
        if(len) {
            [_data appendBytes:(const void *)buf length:len];
            [bytesRead setIntValue:[bytesRead intValue]+len];
        }
        [self readBytes];
        break;
    case NSStreamEventOpenCompleted:
        NSLog(@"NSStreamEventOpenCompleted");
        break;
    case NSStreamEventEndEncountered:
        NSLog(@"NSStreamEventEndEncountered");
        break;
    case NSStreamEventErrorOccurred:
        NSLog(@"An error occurred on the input stream.");
        break;
    }
}

I’ve left out oStream setup from this post to keep it minimal.

I have not sent a request to the FTP to switch to ssl yet.

Any help is greatly appreciated as I find Xcode quite horrible for debugging (no exception or error msg on failed steps what so ever).

  • Chuck
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:55:29+00:00Added an answer on May 14, 2026 at 5:55 am

    See Polling Versus Run-Loop Scheduling. Note the key word versus.

    Further, I don’t think it’s fair to blame Xcode’s debugging capabilities. Xcode is the IDE and works quite well for debugging. The API is what should be raising exceptions (or returning nil) when something goes wrong and I’ve never had a problem setting a breakpoint on objc_exception_throw() or -[NSException raise] to catch exceptions during my debugging sessions.

    Another point to consider: You have no guard code whatsoever. This means you’re ignoring the possibility that a connection might not be established successfully. Part of error detection is making sure your own code detects and handles failures, especially where network communications are involved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apparently, using AttachDbFilename and user instance in your connection string is a bad way
A web application has no make file unlike C++ or anything like that. However,
From reading many articles, such as How do I include a JavaScript file in
I got a Samsung Smart TV UE40D8000 (Apparently from 2011 series ?) and an
ATL uses thunks to manage callbacks for windows, and apparently it needs to allow
So from scouring the internet I managed to find an apparently working Google Voice
I have someone complaining that www.archstl.org (a site I manage) loads fine from his
Apparently, I don't understand how constructors work. When my application starts, it automatically or
A site I manage has seen a sudden drop in visits from google. It
During my work on this database application, I've apparently managed to corrupt a form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.