1

ある場所に1つのファイルとしてアップロードすることにより、2つの大きなファイルをftpサーバーにアップロードしようとしています。ファイルが小さい場合は機能しますが、ファイルが大きい場合はクラッシュします。

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)
            errorReporting(ex.Message.ToString & fileItem)
        End Try
    Next

    swriter.Close()
    swriter.Dispose()
4

2 に答える 2

1

以下は実際に機能し、最終的に10GB +ファイルをアップロードできます

            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()
于 2012-12-17T02:04:12.887 に答える
0
   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

チャンクで書き込むことによってアップロードされます。

于 2011-05-11T14:36:27.693 に答える