通过FTP下载获取文件大小 [英] Get file size on FTP download

查看:1523
本文介绍了通过FTP下载获取文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SimpleFTPSample 进行测试从苹果项目了解如何与iOS的FTP工作。

im testing around with the "SimpleFTPSample" project from apple to understand how ftp with iOS works. i have added two lines in the "GetController.m" to get the size of the file to download.

-(void)_startReceive
{
.
.
.
  // Open a CFFTPStream for the URL.
  ftpStream = CFReadStreamCreateWithFTPURL(NULL, (CFURLRef) url);
  CFReadStreamSetProperty(ftpStream, kCFStreamPropertyFTPFetchResourceInfo, kCFBooleanTrue); // Added: To get file size
.
.
.
}

- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
{
.
.
.
  switch (eventCode) {
    case NSStreamEventOpenCompleted: {
      // Added: Finally get filesize
      fileSize = [[self.networkStream propertyForKey:(id)kCFStreamPropertyFTPResourceSize] integerValue]; 
      [self _updateStatus:@"Opened connection"];
    } break;
.
.
.
}

现在我得到正确的文件大小(fileSize)没有开始。 NSStreamEventHasBytesAvailable情况将不会被处理。我怎样才能使这工作?失败在哪里?我想显示下载状态的进度条 - 所以我需要完整的文件大小。

now i get the correct file size (fileSize) but after that the download won't start. the "NSStreamEventHasBytesAvailable" case won't be handled. how can i get this to work? where's the failure? i want to show a progress bar for the download state- so i need the complete filesize before.

我希望你能帮助我解决这个问题。
thanks!

i hope you can help me out with this. thanks!

推荐答案

要获得您需要的文件大小:

To get the file size you just need:

case NSStreamEventOpenCompleted: {
      fileSize = [[self.networkStream propertyForKey:(id)kCFStreamPropertyFTPResourceSize] integerValue];}

顺便说一句,您知道如何在ftp服务器中获取文件的修改日期吗?

By the way do you know how to get the modification date of the file in the ftp server??

这篇关于通过FTP下载获取文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆