ftp upload of multiple large files into one file
I am trying to upload 2 large files to a ftp server by uploading as one file to a location. I have it working if the files are small but it crashes with large files.
For i As Integer = 0 To filelist.Count() - 1
Dim fRequest As FtpWebRequest = WebRequest.Create(ftpPath & "/Reports/" & filelist.Item(i))
fRequest.Credentials = New NetworkCredential(username, psswd)
fRequest.KeepAlive = False
fRequest.Proxy = Nothing
fRequest.UsePassive = True
fRequest.UseBinary = True
fRequest.Method = WebRequestMethods.Ftp.DownloadFile
fRequest.Timeout = 30000
Try
' read in file...
' upload file...
Dim fresponse As FtpWebResponse = DirectCast(fRequest.GetResponse(), FtpWebResponse)
Dim fstream As FileStream = fileobj.OpenRead()
Dim sStream As Stream = fRequest.GetRequestStream()
Dim reader As New StreamReader(fstream)
swriter.WriteLine(reader.ReadToEnd)
swriter.Flush()
fstream.Close()
fRequest.Abort()
Catch ex As Exception
appLogs.constructLog(ex.Message.ToString & " @ ", True, True)
开发者_Go百科 errorReporting(ex.Message.ToString & fileItem)
End Try
Next
swriter.Close()
swriter.Dispose()
The Below actually works and i can finally upload 10gb + files
Dim bytesread As Byte = 0
Dim buffer As Integer = 2
Dim fRequest As FtpWebRequest = WebRequest.Create(UPloaddir & "/" & filenameup & ".bak")
' fRequest.Credentials = New NetworkCredential(username, psswd)
fRequest.KeepAlive = False
fRequest.Proxy = Nothing
fRequest.UsePassive = True
fRequest.UseBinary = False
fRequest.Method = WebRequestMethods.Ftp.UploadFile
fRequest.Timeout = 180000
' Try
' read in file...
Dim fs As FileStream = File.OpenRead(folder & "\" & fi.Name)
Dim bFile As Byte() = New Byte(1) {}
Dim fstream As Stream = fRequest.GetRequestStream
' upload file...
Do
bytesread = fs.Read(bFile, 0, buffer)
fstream.Write(bFile, 0, bFile.Length)
Loop Until bytesread = 0
fstream.Close()
fstream.Dispose()
Dim filename As String = fileobj.Name
Dim bytesread As Integer = 0
Dim buffer As Integer = 8100
Dim fRequest As FtpWebRequest = WebRequest.Create(ftpPath & "/Logs/" & filename)
fRequest.Credentials = New NetworkCredential(username, psswd)
fRequest.KeepAlive = False
fRequest.Proxy = Nothing
fRequest.UsePassive = True
fRequest.UseBinary = False
fRequest.Method = WebRequestMethods.Ftp.UploadFile
fRequest.Timeout = 180000
Try
' read in file...
'Dim reader As New StreamReader(fileItem)
Dim fs As FileStream = File.OpenRead(fileItem)
Dim bFile As Byte() = New Byte(8100) {}
Dim fstream As Stream = fRequest.GetRequestStream
' upload file...
Do
bytesread = fs.Read(bFile, 0, buffer)
fs.Read(bFile, 0, buffer)
fstream.Write(bFile, 0, bFile.Length)
Loop Until bytesread = 0
fstream.Close()
fstream.Dispose()
Catch ex As Exception
appLogs.constructLog(ex.Message.ToString & " @ ", True, True)
errorReporting(ex.Message.ToString & fileItem)
End Try
uploaded by writing in chunks.
精彩评论