Please considering the code below, it works very well with Small files (Less than 50 MB) but files with 100MB or more, it crashed. and give following error.
“Unable to write data to the transport connection: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.”
'Method
Private Sub Upload(ByVal source As String, ByVal target As String, ByVal credential As NetworkCredential)
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(target), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = credential
request.Proxy = Nothing
Dim reader As New FileStream(source, FileMode.Open)
Dim buffer(Convert.ToInt32(reader.Length - 1)) As Byte
reader.Read(buffer, 0, buffer.Length)
reader.Close()
request.ContentLength = buffer.Length
Dim stream As Stream = request.GetRequestStream
stream.Write(buffer, 0, buffer.Length)
stream.Close()
Dim response As FtpWebResponse = DirectCast(request.GetResponse, FtpWebResponse)
response.Close()
End Sub
'Calling Function
Dim credential As New NetworkCredential("FTPUserName", "FTPPassword")
Upload(FileName.Zip, "ftp://abc.com/Location/FileName.Zip", credential)
Please give advise what I am missing.
Please use this script. works great and I have tested it with 200+ GB of file.
Thanks