Solved

FTPgetFileSize return values

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
Adapt this command to show who installed 29 108
ORA-01403: no data found 43 98
has22 challenge 11 92
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 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

9 Experts available now in Live!

Get 1:1 Help Now