• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Downloading via FTP
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Downloading via FTP


  • Subject: Downloading via FTP
  • From: "Alex S" <email@hidden>
  • Date: Sun, 24 Aug 2008 09:34:53 -0400

I have created a download function but I get an access error when trying to register my client;
#define kMyBufferSize 32000        //download buffers

typedef struct MyStreamInfo {
    CFWriteStreamRef  writeStream;
    CFReadStreamRef   readStream;
    CFDictionaryRef   proxyDict;
    SInt64            fileSize;
    UInt32            totalBytesWritten;
    UInt32            leftOverByteCount;
    UInt8             buffer[kMyBufferSize];
   
} MyStreamInfo;

-(void)download:(NSString *)url withFileName:(NSString *)fileName; {
   
    //create a CFURL from string
    CFURLRef ftpurl = CFURLCreateWithString(kCFAllocatorDefault, (CFStringRef)url, NULL);//NULL means url is absolute
    MyStreamInfo myStreamInfo;
    //create a read stream for the file to be downloaded
    myStreamInfo.readStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, ftpurl);
   
    //create a write stream for the local location where the file is to be saved
    //create the path to file first, the folder downloaded must be created seperatly
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePathString = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",fileName]];
    // create the file URL that identifies the file that the downloader saves into
    CFURLRef fileURL =    CFURLCreateWithFileSystemPath (
                                                       NULL,
                                                       (CFStringRef)filePathString,
                                                       kCFURLPOSIXPathStyle,
                                                       false
                                                       );
   
    myStreamInfo.writeStream = CFWriteStreamCreateWithFile(kCFAllocatorDefault, fileURL);

    //open the write stream
    OSStatus result = CFWriteStreamOpen(myStreamInfo.writeStream);
    if (result != 0) NSLog(@"Result for CFWriteStreamOpen = %d", result);
   
    CFStreamStatus status = CFWriteStreamGetStatus(myStreamInfo.writeStream);
    NSLog(@"CFStreamStatus writeStatus = %d", status);
    CFStreamClientContext dataStreamContext = {0, NULL, NULL, NULL, NULL};
    dataStreamContext.info = &myStreamInfo;
    CFOptionFlags events = kCFStreamEventHasBytesAvailable  | kCFStreamEventEndEncountered | kCFStreamEventOpenCompleted | kCFStreamEventErrorOccurred;

    CFReadStreamSetClient(myStreamInfo.readStream, events, readStreamCallback, &dataStreamContext);
    NSLog(@"ReadStreamSetClient");
    CFReadStreamScheduleWithRunLoop(myStreamInfo.readStream, CFRunLoopGetCurrent(),  kCFRunLoopCommonModes);
}


Alsways crashes on this line. Any advice?
CFReadStreamSetClient(myStreamInfo.readStream, events, readStreamCallback, &dataStreamContext);
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: AudioDeviceGetProperty error
  • Next by Date: Test report MBP built-in audio device
  • Previous by thread: Re: AudioDeviceGetProperty error
  • Next by thread: Test report MBP built-in audio device
  • Index(es):
    • Date
    • Thread