请考虑下面的代码,它适用于小文件(小于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)
请告知我缺少的东西。
答案 0 :(得分:1)
请使用此脚本。效果很好,我用200多GB的文件测试了它。
Private Sub Upload(ByVal sourceFiles() As String)
Dim cm As ConnectionManager = Dts.Connections.Add("FTP")
cm.Properties("ServerName").SetValue(cm, Dts.Variables("User::FTPServerName").Value.ToString())
cm.Properties("ServerUserName").SetValue(cm, Dts.Variables("User::FTPUserName").Value.ToString())
cm.Properties("ServerPassword").SetValue(cm, Dts.Variables("User::FTPPassword").Value.ToString())
cm.Properties("ServerPort").SetValue(cm, "21")
cm.Properties("Timeout").SetValue(cm, "0")
cm.Properties("ChunkSize").SetValue(cm, "1000")
cm.Properties("Retries").SetValue(cm, "1")
Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
ftp.Connect()
ftp.SendFiles(sourceFiles, Dts.Variables("User::FTPFolder").Value.ToString(), True, False)
ftp.Close()
End Sub
由于