Forum > Networking and Web Programming
Lnet FTP problem with large files in Win64
cybersmyth:
I'm not totally sure what the problem is, but I think it's got something to do with Windows 64bit. I built a routine based on the lnet visual FTP example and it works great on my Linux machine (which is 32bit). I run it on my Windows machine and it compiles and runs fine until it suddenly doesn't. %)
I tried a lot of stuff and finally figured out it's large files that are giving me the trouble. I don't know exactly how big they have to get before there is an issue, but it definitely has something to do with larger files. Small text and image files copy over fine.
I thought I had screwed something up so I tried the lnet visual example and ran into the same problem! So I'm totally lost, no clue and am only guessing it has to do with 32 vs 64 because I could swear I've gotten this routine to work on a 32bit system before, but not 100% sure. But I am 100% sure it works fine on Linux 32bit.
Here is the problem area:
--- Code: ---...
var
s: string;
i: Integer;
Buf: array[0..65535] of Byte;
begin
if FTP.CurrentStatus = fsRetr then begin // getting file, save to file
i := FTP.GetData(Buf, 65535);
if i > 0 then begin
if Length(CreateFilePath) > 0 then begin
FFile := TFileStream.Create(CreateFilePath, fmCreate or fmOpenWrite);
CreateFilePath := '';
end;
FFile.Write(Buf, i);
end else begin
// file download ended
...
--- End code ---
The crash happens at FFile.Write(Buf, i); after it writes 70 bytes or so.
Thanks for any help.
Almindor:
This is really odd, it doesn't seem connected to lNet itself since you get a crash a TFIleStream.Write..
Perhaps try to write a standalone application which just copies a file like this on given platform. Perhaps you actually hit a hard disk problem?
Is it reproducable? If the FTP server/file is accessible send me the URL/name and I could try here too (although I only have win32 XP)
Also what crash is it exactly? Can you try to compile FPC source with -gl and see if you get debug info inside the file stream.
fabienwang:
Buf: array[0..65535] of Byte; << shouldn't it be 65534 ?
motaz:
it is better to use SizeOf function:
--- Code: --- i := FTP.GetData(Buf, SizeOf(Buf));
--- End code ---
Almindor:
You're right that it's odd usage (yeah.. my fault) but this cannot cause such problems.
Buffer size is 65536 (0..65535) and max 65535 bytes is read in GetData.
FFile.Write gets always a positive number (if i > 0) but <= 65535 (GetData limit) so it should work fine.
There's a bit of a discrepancy in the code but there's no bounds problem as far as I can say.
You need to provide a backtrace otherwise we're fishing in the dark.
Navigation
[0] Message Index
[#] Next page