其實ios的FTP下載非常簡單 。其實就是下載數據流。和其他文件下載是一樣的。
有兩種方法
第一種 適合小文件

1 //替換字符 2 3 NSString* strPath = [builder.Path stringByReplacingOccurrencesOfString:@"\\" withString:@"/"]; 4 strPath = [strPath stringByReplacingOccurrencesOfString:@"//" withString:@"/"]; 5 //下載鏈接 6 NSString * fileStream = [NSString stringWithFormat : @"%@%@:%@%@%@%@",@"ftp://", builder.USER_NAME, builder.USER_PWD,@"@" ,builder.HOST_NAME,strPath]; 7 NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString: fileStream]];
fileStream:就是下載地址 ftp://USER_PWD:USER_PWD@999.99.999.99/carNet/File/ARCHIVE/2017/10/16/201710161001/1/asd/asdfgChinaSRV02_172.31.132.244_201710161633073.dat
第二種:

1 NSURL *url=[NSURL URLWithString:fileStream]; 2 //設置請求超時 3 NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url]; 4 request.timeoutInterval=5.0; 5 //發送請求 6 //使用代理發送異步請求(通常應用於文件下載)'connectionWithRequest:delegate:' is deprecated: first deprecated in iOS 9.0 - U 7 // NSURLConnection *conn=[NSURLConnection connectionWithRequest:request delegate:self]; 8 NSURLSession *session = [NSURLSession sharedSession]; 9 NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 10 completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) 11 { 12 // do something with the data 13 NSData *data1111 =data; 14 NSLog(@"dffffff%@",data1111); 15 }]; 16 [dataTask resume];
在我打log的時候我發現nsdata 里面下載的內容顯示不全。一開始我以為是我下載的問題。又研究沙盒,有研究長度。后來我把數據移到nsdata上 直接查看。發現其實已經下載全了。是nslog的顯示不全。