iddober
iddober

Reputation: 1264

Get File Size of File to download using FTP

I am using the simpleFTPsample of apple. I want to display a progress bar of the file being downloaded. I understand it needs to be done in:
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
under the case:
case NSStreamEventOpenCompleted:

how do i retrive the file size from the NSInputStream?

I have also tried:

i have set:
[self.networkStream setProperty:@"YES" forKey:(id)kCFStreamPropertyFTPFetchResourceInfo];
and then:
NSLog(@"size: %@",[self.networkStream propertyForKey:(id)kCFStreamPropertyFTPResourceSize]);
but the result is null...

Upvotes: 0

Views: 1593

Answers (2)

Frade
Frade

Reputation: 2988

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??

Upvotes: 0

Stefan Arentz
Stefan Arentz

Reputation: 34945

You will have to set kCFStreamPropertyFTPFetchResourceInfo to true. That way the CFFTPStream will send a STAT command to the FTP server to get file info, including the total size.

Upvotes: 2

Related Questions