Solved

FTPgetFileSize return values

Posted on 2009-04-15
4
2,186 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 97
dog bark java program 15 120
move a line in eclipse 3 109
wordcount challenge 11 145
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

763 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