获取 FTP 下载的文件大小

发布于 2024-11-04 03:12:58 字数 1023 浏览 0 评论 0原文

我正在使用“SimpleFTPSample”项目进行测试apple 了解 ftp 在 iOS 上的工作原理。我在“GetController.m”中添加了两行来获取要下载的文件的大小。

-(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”情况将不会被处理。我怎样才能让它发挥作用?失败在哪里?我想显示下载状态的进度条 - 所以我之前需要完整的文件大小。

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

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;
.
.
.
}

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青朷 2024-11-11 03:12:58

我非常确定,当您设置 kCFStreamPropertyFTPFetchResourceInfo 时,这意味着您只对该特定请求中的资源大小感兴趣。

您可能应该创建一个新的控制器,它是 GetController 的子类,将其命名为 StatController... 将 _startReceive 和流处理程序重写为您的新方法。

在开始异步下载之前,使用 StatController 获取资源大小。

I am pretty sure that when you set kCFStreamPropertyFTPFetchResourceInfo, that means your are only interested in the resources size in that particular request.

you should probably make a new controller that is a subclass of GetController, call it StatController... override _startReceive and the stream handler to your new methods.

use the StatController to get the resource size before you start the async download.

携余温的黄昏 2024-11-11 03:12:58

要获取文件大小,您只需要:

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

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

To get the file size you just need:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文