请考虑下面的代码,它适用于小文件(小于 50 MB),但 100 MB 或更大的文件会崩溃。并给出以下错误。
“无法将数据写入传输连接:无法对套接字执行操作,因为系统缺少足够的缓冲区空间或队列已满。”
'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)
请告诉我我错过了什么。