我正在制作一个可以从受用户名和密码文件保护的 FTP 服务器下载并将其保存在文档目录中的应用程序。我已经设法直接从 HTTP 下载文件,保存并显示它。现在我希望通过 FTP 这样做。这是我的代码:
-(IBAction)download:(id)sender
{
NSString *stringURL = @"http://www.image.png";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"filename3.png"];
[urlData writeToFile:filePath atomically:YES];
}
}
-(IBAction)viewImage:(id)sender
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"filename3.png"];
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
[imageV setImage:img];
}
谁能指点我CFNetwork的例子。我需要连接到 ftp 服务器,列出文件夹中的文件并下载它们。已经看过http://developer.apple.com/library/ios/#Documentation/Networking/Conceptual/CFNetwork/CFFTPTasks/CFFTPTasks.html#//apple_ref/doc/uid/TP30001132-CH9-SW1但它不是非常明了。