Baladash
Baladash

Reputation: 1

Write String to file to FTP Objective C?

I am attempting to take the string value of a UITextField, put that into a txt file, then send it to my FTP server.

I have looked at SimpleFTPSample from apple and have reviewed its code to the best of my abilities. I have been programming in Objective C only about a month or so but i thought i had a somewhat working knowledge of how this worked so i wrote out this code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
    NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/tobesent.txt", documentsDir];

[txttext.text writeToFile:fileName atomically:NO encoding:NSUTF8StringEncoding error:nil];
NSURL *url = [[NSURL alloc]initWithString:@"ftp://USERNAME:PASSWORD@LOCATION/tobesent.txt"];
NSInputStream *fileStream;
NSOutputStream *networkStream;

fileStream = [NSInputStream inputStreamWithFileAtPath:fileName];
[fileStream open];
networkStream = CFBridgingRelease(CFWriteStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url));
networkStream.delegate = self;
[networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[networkStream open];

All this seems to do is create the file named "tobesent.txt" in my FTP server without any data in it even though i do put data in txttext.text. I also know that there are other things i can download in order to make this process more simple but i really would like to see if i can get this accomplished without them. Any help is much appreciated!

Upvotes: 0

Views: 397

Answers (2)

xyzzycoder
xyzzycoder

Reputation: 1831

You may want to check out libCurl - http://curl.haxx.se/libcurl/

Upvotes: 0

Chuck
Chuck

Reputation: 237100

You aren't actually sending any data. You create an NSInputStream from a file and never do anything with it, and you create an NSOutputStream to a file on the server and never do anything with it. You want to read from the input stream and write to the output stream.

Upvotes: 1

Related Questions