我不知道如何在 iPhone 上制作 FTPS(基于 SSL 的 FTP)。我想使用以下代码
ftpStream = CFWriteStreamCreateWithFTPURL(NULL, (CFURLRef) url);
CFWriteStreamSetProperty(ftpStream, kCFStreamPropertyFTPUserName,username);
CFWriteStreamSetProperty(ftpStream, kCFStreamPropertyFTPPassword,password);
self.networkStream = (NSOutputStream *) ftpStream;
[self.networkStream setProperty:NSStreamSocketSecurityLevelSSLv3 forKey:(id)NSStreamSocketSecurityLevelKey];
self.networkStream.delegate = self;
[self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];
...
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
{
NSLog(@"Hello\n");
}
此代码连接到服务器,但随后停止通话。我也尝试过使用以下设置安全级别
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
(NSString *)kCFStreamSocketSecurityLevelSSLv3, kCFStreamSSLLevel,
kCFBooleanTrue, kCFStreamSSLAllowsAnyRoot,
kCFBooleanFalse, kCFStreamSSLValidatesCertificateChain,
hostName, kCFStreamSSLPeerName,
kCFBooleanFalse, kCFStreamSSLIsServer,
kCFBooleanFalse,kCFStreamSSLValidatesCertificateChain,
kCFBooleanTrue, kCFStreamSSLAllowsExpiredCertificates,
kCFBooleanTrue, kCFStreamSSLAllowsExpiredRoots,
nil];
CFWriteStreamSetProperty(ftpStream, kCFStreamPropertySSLSettings, settings);
这允许我连接和传输数据,但不能通过 SSL。
知道我做错了什么。