I am using vb.net(.Net 4.0) to upload the File to server using ftp.
i could upload file small size(10MB,) without any error. but when i Try for uploading more than 2GB size it lead the following Error
System.OverflowException: Value was either too large or too small for an Int32.
I am using the code..
Private Function UploadFileToServer(ByVal sSourceFile As String, ByVal sTargetFile As String) As Boolean
Dim objCredential As NetworkCredential
Dim objRequest As FtpWebRequest
Dim objReader As FileStream
Dim objStream As Stream
Dim objResponse As FtpWebResponse
Dim bResult As Boolean = False
Try
objRequest = DirectCast(WebRequest.Create(sTargetFile), FtpWebRequest)
'objRequest = FtpWebRequest.Create(sTargetFile)
objRequest.Method = WebRequestMethods.Ftp.UploadFile
objCredential = New NetworkCredential(USER_NAME, PASSWORD)
objRequest.Credentials = objCredential
objReader = New FileStream(sSourceFile, FileMode.Open)
Dim objBuffer(Convert.ToInt32(objReader.Length - 1)) As Byte
objReader.Read(objBuffer, 0, objBuffer.Length)
objReader.Close()
objRequest.ContentLength = objBuffer.Length
objStream = objRequest.GetRequestStream()
objStream.Write(objBuffer, 0, objBuffer.Length)
objStream.Close()
objResponse = DirectCast(objRequest.GetResponse, FtpWebResponse)
objResponse.Close()
bResult = True
Catch ex As Exception
End Try
Return bResult
End Function
it shows the error on this line
Dim objBuffer(Convert.ToInt32(objReader.Length - 1)) As Byte
Can any one please help me.
Thanks,
Senthil