对于我的应用程序,我正在尝试
发现这件事令人惊讶地复杂。
在尝试了ConnectionKit (几乎没有文档)、NMSSH (在同时上传时经常崩溃一次)、rsync (服务器不支持)、sftp (如果脚本需要密钥身份验证、用户名/密码不起作用),我现在回到ConnectionKit:https://github.com/karelia/ConnectionKit。
但是,我正在努力应对身份验证挑战,因为我不知道如何处理委托方法中的凭据。
但这正是我所奋斗的地方:我知道如何创建一个NSURLCredential,但是,我不知道如何使用它-- =>
- (void)fileManager:(CK2FileManager *)manager
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSURLCredential *credentials = [NSURLCredential
credentialWithUser:self.username
password:[self getPassword]
persistence:NSURLCredentialPersistenceForSession];
// what to do now?
// [manager useCredential:] doesn’t exist, nor is there a manager.connection?
// ...
}我已经读了标题,我搜索了这个列表的档案,但是所有的答案似乎都过时了。我还搜索了谷歌、必应和StackOverflow,并找到了一个从2011年开始使用CKFTPConnection的很有希望的例子,这个例子似乎不再包含在当前的框架中。
非常感谢任何指向正确方向的指针。
tl;dr
我不知道如何响应ConnectionKit的CK2FileManager authenticationChallenge:参见代码示例中的注释
发布于 2014-01-18 00:36:26
对于CK2:
- (void)listDirectoryAtPath:(NSString *)path
{
// path is here @"download"
NSURL *ftpServer = [NSURL URLWithString:@"sftp://companyname.topLevelDomain"];
NSURL *directory = [CK2FileManager URLWithPath:path isDirectory:YES hostURL:ftpServer];
CK2FileManager *fileManager = [[CK2FileManager alloc] init];
fileManager.delegate = self;
[fileManager contentsOfDirectoryAtURL:directory
includingPropertiesForKeys:nil
options:NSDirectoryEnumerationSkipsHiddenFiles
completionHandler:^(NSArray *contents, NSError *error) {
if (!error) {
NSLog(@"%@", contents);
} else {
NSLog(@"ERROR: %@", error.localizedDescription);
}
}];
}而不是您必须实现以下协议
- (void)fileManager:(CK2FileManager *)manager operation:(CK2FileOperation *)operation
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(CK2AuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
if (![challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodDefault]) {
completionHandler(CK2AuthChallengePerformDefaultHandling, nil);
return;
}
NSString * username = @"<username>";
NSString * pathToPrivateSSHKey = @"</Users/myNameOnLocalMaschine/.ssh/id_rsa>"
NSURLCredential *cred = [NSURLCredential ck2_credentialWithUser:username
publicKeyURL:nil
privateKeyURL:[NSURL fileURLWithPath:pathToPrivateSSHKey]
password:nil
persistence:NSURLCredentialPersistenceForSession];
completionHandler(CK2AuthChallengeUseCredential, cred);
}就这样。
调用-listDirectoryAtPath:,然后在内容数组中的完成处理程序块中获得位于给定路径上的所有文件:)
https://stackoverflow.com/questions/19999638
复制相似问题