Hi all,
I am a beginner iPhone developer and I'm writing an app to upload a set of local files to an FTP server.
I started from the SimpleFTPSample application, then I modified it in order to upload N files in a row, but
only one file is uploaded.
I also implemented the solution described in the "
Working with FTP Server" page (with the callback and all) but I got the same behaviour.
These are my steps (for each file).
Code:
// Open the file stream ('t' is a structure containing the fileName and read/write streams)
CFURLRef fileNameURL = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)t.fileName, kCFURLPOSIXPathStyle, FALSE);
t.readStream = CFReadStreamCreateWithFile(NULL, fileNameURL);
CFReadStreamOpen(t.readStream);
CFStreamStatus streamStatus = CFReadStreamGetStatus(t.readStream);
assert(streamStatus == kCFStreamStatusOpening || streamStatus == kCFStreamStatusOpen);
// Create the FTP stream
t.writeStream = CFWriteStreamCreateWithFTPURL(NULL, (CFURLRef)t.ftpURL);
// Register the callback
context.info = t;
CFWriteStreamSetClient(t.writeStream, kCFStreamEventCanAcceptBytes|kCFStreamEventErrorOccurred|FStreamEventEndEncountered, CFWriteStreamClientCallBack)&writeStreamCallback, &context);
// 'writeStreamCallback' reads chunks of bytes from readStream and writes them to writeStream
// Schedule in RunLoop
[(NSStream*)t.writeStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
// Open the FTP stream (this should start the transfer)
CFWriteStreamOpen(t.writeStream);
stramStatus = CFWriteStreamGetStatus(t.writeStream);
assert(streamStatus == kCFStreamStatusOpening || streamStatus == kCFStreamStatusOpen);
The callback function is not called immediately after I open the FTP stream, but after a while (possibly it starts at the beginning of the following RunLoop, but just guessing…).
If I schedule more writeStreams in RunLoop, only the first one is executed.
I also tried to spin a new thread for each file to be uploaded (since, from my understanding, each NSThread has its own RunLoop) but it didn't work.
Could you please give me any hints?
Thank you,
Rippel