HugoBoss
HugoBoss

Reputation: 95

Special character from FTP directory

i´m using the black raccoon class for ftp sessions. getting the content of a FTP directory like this

arrayHelper.FTPFileName = [file objectForKey:(id)kCFFTPResourceName]

and writing into nsmutablearray

i have some folders with special character like this on the ftp share:

"Heino - Mit Freundlichen Gr\U00b8ssen (Deluxe Edition) (2013) - 320"

How can i convert the string?

i´ve try´ed the following:

NSString *uncodedName = [file objectForKey:(id)kCFFTPResourceName];
        NSLog(@"Uncoded Name is %@",uncodedName);
        arrayHelper.FTPFileName = [NSString stringWithCString:[uncodedName cStringUsingEncoding:NSUTF8StringEncoding]
                                                     encoding:NSNonLossyASCIIStringEncoding];
        NSLog(@"Coded Name is %@",arrayHelper.FTPFileName);

but returns nil...

NSLog:

[7344:c07] Uncoded Name is Heino - Mit Freundlichen Gr¸ssen (Deluxe Edition) (2013) - 320 [7344:c07] Coded Name is (null)

Upvotes: 0

Views: 683

Answers (1)

Martin R
Martin R

Reputation: 539725

One can see in the source code of CFFTPStream.c that CFFTPStream interprets all file names on the FTP server in the "Mac OS Roman" encoding. Your FTP server seems to use Windows encoded file names, which are therefore wrongly converted to Unicode in CFFTPStream.

But you can reverse the process with

NSString *uncodedName = [file objectForKey:(id)kCFFTPResourceName];
NSData *data = [uncodedName dataUsingEncoding:NSMacOSRomanStringEncoding];
arrayHelper.FTPFileName = [[NSString alloc] initWithData:data encoding:NSWindowsCP1252StringEncoding];

Upvotes: 1

Related Questions