Solved

FTPgetFileSize return values

Posted on 2009-04-15
4
2,157 Views
Last Modified: 2013-11-17
Could someone please enlighten me as to what high/low means in the description of this function? So how do you retrieve the filesize then? The description seems a bit scarce. To me at least.

MSDN says:

Parameters
hFile [in]
Handle returned from a call to FtpOpenFile.

lpdwFileSizeHigh [out]
Pointer to the high-order unsigned long integer of the file size of the requested FTP resource.

Return Value
Returns the low-order unsigned long integer of the file size of the requested FTP resource.

---

Actually, I don't have the slightest clue as to why am I required to multiply fileSize by 260. (see in the example.) Apparently, that's the way it should be calculated. So the final filesize is the sum of the aforementioned product and the return value of the function.
//Progress bar maximum

SizeLo = FtpGetFileSize(

  hFileOnFTP,

  fileSize

);
 

PbarMax = ((INT)fileSize* 260) + SizeLo;

Open in new window

0
Comment
Question by:Kyanzes
4 Comments
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 24153329
The interface allows you to receive a file size of up to 64 bits which is too big to fit in a 32-bit unsigned long integer. On a 32-bit platform, unsigned long is usually the same size as unsigned int (i.e. sizeof(unsugned long) == sizeof(unsigned int) == 4). On these platforms, the compiler sometimes offers [unsigned] long long as a 64-bit entity, into which you could accumulate the file size.
Multiplying by 260 is a nonsense - you have to shift left by 32 bits. Casting to INT if INT is 32 bits will give you a zero result so is also wrong. Is fileSize a pointer? - you should not cast it to INT then. If it is not a pointer then you should have got a compiler error on FtpGetFileSize(). Since you get no error, I assume fileSize is of type INT*.
You might well be able to treat nonzero upper file size an error - do you really want to FTP files > 4GB? To actually deal properly with them supposing you don't want to limit file size, try as below. UINT64 is my invention - you'll have to search for what's available. PbarMax should be of type UINT64, and the code sets it to the file size in bytes - it will require scaling to make a progress bar. I have also changed fileSize to be of type UINT (i.e. UINT32) - SizeLo should be UINT32 also. You are doing bitwise operations so use | rather than +
//Progress bar maximum

SizeLo = FtpGetFileSize(

  hFileOnFTP,

  &fileSize

);

 

PbarMax = ((UINT64)fileSize << 32) | SizeLo;

Open in new window

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24153541
To be complete:
Multiplying the filesize value by 260 will work most of the time, since the value of that variable will be 0 most of the time. :-)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now