Jump to content


Photo

DownloadFile Arithmetic operation resulted in an overflow


  • Please log in to reply
12 replies to this topic

#1 NemisisJedi

NemisisJedi
  • Members
  • 8 posts

Posted 28 November 2008 - 12:16 PM

I am using the DownloadFile function via a FTPConnectionMTA and i am getting the following error on this bit of code

ERROR = Arithmetic operation resulted in an overflow.

CODE
mFtp.DownloadFile("REMOTEFILENAME", "LOCALFILENAME", 2148751482, 0)

I am resuming a download of a file that has a remoteSize of 7243113984

Does anyone know why this is happening? I believe that the download is failing as the input is an integer data type which is a max value of 2147483647, and my value is above it. Is this a bug? Should it be a long data type instead of an integer??

Thanks for your help in advanced.

#2 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 28 November 2008 - 01:32 PM

What programming language are you using?

#3 NemisisJedi

NemisisJedi
  • Members
  • 8 posts

Posted 28 November 2008 - 01:40 PM

Vb.NET

#4 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 28 November 2008 - 01:42 PM

Can you post a bit more of the code? Or do you use the numeric 2148751482 in the arguments?

#5 NemisisJedi

NemisisJedi
  • Members
  • 8 posts

Posted 28 November 2008 - 01:49 PM

The value 2148751482 is being passed into the DownloadFile procedure. My code looks like

mFtp.DownloadFile(pRemoteFile, pLocalFileInfo.FullName, pLocalFileSize, 0)

pRemoteFile = Remote File Name
pLocalFileInfo = FileInfo where localfile is to be saved
pLocalFileSize = Long value, containing the length of the file held locally, so a resume download can be done

#6 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 28 November 2008 - 01:53 PM

You have to split the position into 2 32-bit longs. In C# this looks something like that:
DownloadFile(source, dest, (int)pLocalFileSize, (int)(pLocalFileSize >> 32))

#7 NemisisJedi

NemisisJedi
  • Members
  • 8 posts

Posted 28 November 2008 - 01:56 PM

Ok, so i do not need to pass a 0 in as the last parameter, even if i am/am not doing a resume?

#8 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 28 November 2008 - 02:09 PM

It depends on what position you resume.

#9 NemisisJedi

NemisisJedi
  • Members
  • 8 posts

Posted 28 November 2008 - 02:20 PM

I would like to resume at the end of the local file, if the local file exists, else it starts from the beginning

#10 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 28 November 2008 - 02:23 PM

If the local file doesn't exist you use 0,0 for the arguments otherwise you use the method I described in my last post:
DownloadFile(source, dest, (int)pLocalFileSize, (int)(pLocalFileSize >> 32))

Regards,
Mat

#11 NemisisJedi

NemisisJedi
  • Members
  • 8 posts

Posted 01 December 2008 - 10:28 AM

The code seems to be moving along further now, but i am now getting the same error "Arithmetic operation resulted in an overflow." with the value of 7280103424.

I have changed my code to the following

downloadStatus = mFtp.DownloadFile(pTargetFile, localFile.FullName, CInt(localFileSize), CInt((localFileSize >> 32)))

Is DownloadFile the best download method to use, what is the difference with DownloadFile and DownloadFileEx and DownloadFileEx2??

DownloadFileEx2 seems to allow for Long datatype inputs, but i am not sure what the CreateDeposition parameter means and what i should pass in for it??

#12 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 01 December 2008 - 03:36 PM

Try something like this for the 3rd argument:
CInt(localFileSize & 0xffffffff)

#13 NemisisJedi

NemisisJedi
  • Members
  • 8 posts

Posted 05 December 2008 - 09:39 AM

That works perfectly, thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users