Overflow-Exception at Upload

Apr 5, 2013 at 11:45 AM
Edited Apr 5, 2013 at 12:08 PM
Hi again,

A large File:
http://s1.directupload.net/images/130404/9gv4ya6d.png
Image

produces this Exception:
(ArithmeticException / Overflow-Exception)
http://s1.directupload.net/images/130404/2zycwnfa.png
Image

in line:
Dim bytes As Byte() = New Byte(CInt((fileinput.Length) - 1)) {}
in full code:
Private Sub Upload(ByVal filename As String, ByVal remotepath As String) 
ftpclient.Host = sFtpHost : ftpclient.Credentials = credentials : ftpclient.EncryptionMode = FtpEncryptionMode.Explicit 
AddHandler ftpclient.ValidateCertificate, AddressOf SSLcertificateHandler 
Using ftpclient 
Using outputstream As Stream = ftpclient.OpenWrite(Chr(34) + remotepath + Chr(34)) 
Dim fileinput As New FileStream(filename, FileMode.Open, FileAccess.Read)
Try  Dim bytes As Byte() = New Byte(CInt((fileinput.Length) - 1)) {} 
 Dim numBytesToRead As Integer = CType(fileinput.Length, Integer) 
 Dim numBytesRead As Integer = 0
While (numBytesToRead > 0) 
 Dim n As Integer = fileinput.Read(bytes, numBytesRead, numBytesToRead)  If (n = 0) Then
 Exit While 
 End If 
 numBytesRead = (numBytesRead + n) : numBytesToRead = (numBytesToRead - n) 
 End While
numBytesToRead = bytes.Length  outputstream.Write(bytes, 0, numBytesToRead)
Finally 
 fileinput.Close() : outputstream.Close() 
 End Try  End Using  End Using
End Sub
The exception also says that I should not divide through zero. How do I modify the method to be able to upload large files?
Apr 5, 2013 at 12:06 PM
I also don't like that in my current state, he always logs in and out for every single upload. Thus AUTH TLS is called for every file. That slows the Uploading for a large amount of small files a lot.

I call the upload here:
        If listLocalFiles.Count <> 0 Then
            SetBalloonTip("Uploadfortschritt: 0 / " + listLocalFiles.Count.ToString, 1000, True)

            ftpclient.Host = sFtpHost : ftpclient.Credentials = credentials : ftpclient.EncryptionMode = FtpEncryptionMode.Explicit
            AddHandler ftpclient.ValidateCertificate, AddressOf SSLcertificateHandler
            For Each element In listLocalFiles
                Dim destinationPath As String = element.FullName.Replace(sLocalDir, sRemoteDir).Replace("\", "/")
                Upload(element.FullName, destinationPath) : uploadCount += 1 ' Datei per Stream hochladen
                SetBalloonTip("Uploadfortschritt: " + uploadCount.ToString + "/" + listLocalFiles.Count.ToString, 1000, True)
            Next
        End If
Coordinator
Apr 5, 2013 at 1:56 PM
Don't try to allocate a buffer the size of the file, which in this case is 3.23 GB. All you're doing is wasting 3.23 GB of the the local machines ram if it were to ever work at all. Your buffer size should probably be around 8K, 8192.
Coordinator
Apr 5, 2013 at 1:59 PM
I also don't like that in my current state, he always logs in and out for every single upload.
I've told you repeatedly to disable thread safe data channels. If you don't need thread safety turn it off and only 1 control connection will be used.
Apr 5, 2013 at 2:04 PM
jptrosclair wrote:
I also don't like that in my current state, he always logs in and out for every single upload.
I've told you repeatedly to disable thread safe data channels. If you don't need thread safety turn it off and only 1 control connection will be used.
I thought i disabled this. I'll debug through and make sure that it is still set when the upload is called.