Created
June 21, 2014 05:29
-
-
Save t-oginogin/bdcdf0a6e1ab8b547563 to your computer and use it in GitHub Desktop.
Objective-CのFTPファイル送受信で日本語名ファイルを扱う ref: http://qiita.com/t_oginogin/items/6ed62df0db6c7034bc49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)requestsManager:(id<GRRequestsManagerProtocol>)requestsManager didCompleteListingRequest:(id<GRRequestProtocol>)request listing:(NSArray *)listing | |
| { | |
| NSLog(@"requestsManager:didCompleteListingRequest:listing: \n%@", listing); | |
| self.fileLists = nil; | |
| self.fileLists = [[NSMutableArray alloc] init]; | |
| // 日本語ファイル名の変換 | |
| NSString *name; | |
| NSData *nameData; | |
| NSString *newName; | |
| for (int i = 0; i<[listing count]; i++) { | |
| name = listing[i]; | |
| nameData = [name dataUsingEncoding:NSMacOSRomanStringEncoding]; | |
| if (nameData != nil) { | |
| newName = [[NSString alloc] initWithData:nameData encoding:NSShiftJISStringEncoding]; | |
| [self.fileLists addObject:newName]; | |
| } | |
| } | |
| self.getButton.enabled = YES; | |
| [self.fileListView reloadData]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (IBAction)getFile:(id)sender { | |
| [self _setupManager]; | |
| if (self.ftpFileName == nil) { | |
| return; | |
| } | |
| NSData *nameData = [self.ftpFileName dataUsingEncoding:NSShiftJISStringEncoding]; | |
| if (nameData == nil) { | |
| return; | |
| } | |
| NSString *newName = [[NSString alloc] initWithData:nameData encoding:NSMacOSRomanStringEncoding]; | |
| NSString* encodedFileName = [newName stringByAddingPercentEscapesUsingEncoding:NSMacOSRomanStringEncoding]; | |
| [self.requestsManager addRequestForDownloadFileAtRemotePath:encodedFileName toLocalPath:[NSTemporaryDirectory() stringByAppendingPathComponent:self.ftpFileName]]; | |
| [self.requestsManager startProcessingRequests]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (IBAction)putFile:(id)sender { | |
| [self _setupManager]; | |
| NSData *nameData = [self.ftpFileName dataUsingEncoding:NSShiftJISStringEncoding]; | |
| if (nameData == nil) { | |
| return; | |
| } | |
| NSString *newName = [[NSString alloc] initWithData:nameData encoding:NSMacOSRomanStringEncoding]; | |
| NSString* encodedFileName = [newName stringByAddingPercentEscapesUsingEncoding:NSMacOSRomanStringEncoding]; | |
| [self.requestsManager addRequestForUploadFileAtLocalPath:[NSTemporaryDirectory() stringByAppendingPathComponent:self.ftpFileName] toRemotePath:encodedFileName]; | |
| [self.requestsManager startProcessingRequests]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (IBAction)getFile:(id)sender { | |
| [self _setupManager]; | |
| if (self.ftpFileName == nil) { | |
| return; | |
| } | |
| NSData *nameData = [self.ftpFileName dataUsingEncoding:NSShiftJISStringEncoding]; | |
| if (nameData == nil) { | |
| return; | |
| } | |
| NSString *fileName = [[NSString alloc] initWithData:nameData encoding:NSMacOSRomanStringEncoding]; | |
| [self.requestsManager addRequestForDownloadFileAtRemotePath:fileName toLocalPath:[NSTemporaryDirectory() stringByAppendingPathComponent:self.ftpFileName]]; | |
| [self.requestsManager startProcessingRequests]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (IBAction)putFile:(id)sender { | |
| [self _setupManager]; | |
| NSData *nameData = [self.ftpFileName dataUsingEncoding:NSShiftJISStringEncoding]; | |
| if (nameData == nil) { | |
| return; | |
| } | |
| NSString *fileName = [[NSString alloc] initWithData:nameData encoding:NSMacOSRomanStringEncoding]; | |
| [self.requestsManager addRequestForUploadFileAtLocalPath:[NSTemporaryDirectory() stringByAppendingPathComponent:self.ftpFileName] toRemotePath:fileName]; | |
| [self.requestsManager startProcessingRequests]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "GRRequest.h" | |
| @interface GRRequest(Encode) | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "GRRequest+encode.h" | |
| #import <objc/runtime.h> | |
| @implementation GRRequest(Encode) | |
| - (NSString *)encodeString:(NSString *)string; | |
| { | |
| NSString *urlEncoded = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes( | |
| NULL, | |
| (__bridge CFStringRef) string, | |
| NULL, | |
| (CFStringRef)@"!*'\"();:@&=+$,?%#[]% ", | |
| kCFStringEncodingMacRoman); | |
| return urlEncoded; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pod "GoldRaccoon" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment