How do I obtain the size of a file I am about to download with TIdFTP?

Previous  Top  Next

Use the TIdFTP.Size method passing the file name as a parameter.  That method will return the size of a file or -1 if the server does not support the SIZE command.

 

You should never use any data from the TIdFTP.DirectoryListing collection because, on some servers, the most you can only get is an estimate of the file size because the file system is based on records or blocks instead of individual bytes.  You then might be able to estimate a file size with that information.  Sometimes, you can not even calculate an estimate of the file size from that information in the directory listing.  Some FTP directory list formats do not include any file size information at all.  Even when emulating Unix, some mainframes may only return estimated file sizes.