Fast HTTPS Upload Code Needed

Hi all,

I need some fast HTTPS upload Code.

Here's the code I'm currently using.  It's pretty slow, although my download code screams.  While reading the file and writing to the stream is fast, actually sending the data using request.GetResponse is horribly slow.  I'm open to any ideas...


    Public Function UploadFile(ByVal filePath As String, _
                                         ByVal address As String, _
                                         ByRef pb As System.Windows.Forms.ToolStripProgressBar) _
                                         As Boolean

        'Get the length of the selected file
        Dim fi As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(filePath)
        Dim fileLength = fi.Length

        'Create the request
        Dim request As HttpWebRequest = _
            DirectCast(HttpWebRequest.Create(address), HttpWebRequest)

        'Configure request
        request.Credentials = New System.Net.NetworkCredential("user", "password")
        request.Method = WebRequestMethods.Http.Put
        request.ContentLength = fileLength.ToString()

        'This is required for our WebDav server (will error without it)
        request.SendChunked = True
        request.Headers.Add("Translate: f")
        request.AllowWriteStreamBuffering = True

        Dim s As IO.Stream = request.GetRequestStream()
        Dim fs As New IO.FileStream(filePath, IO.FileMode.Open, IO.FileAccess.Read)

        'Number of KiloBytes in the file
        pb.Maximum = CInt(fileLength \ 1024)
        pb.Minimum = 0
        pb.Value = 0
        pb.Visible = True

        Dim bytes(1023) As Byte              '1024 bytes
        Dim bytesRead As Integer = 0
        Dim totalBytesRead As Long = 0

        '*** EVERYTHING HERE IS FAST ***
        Do
            bytesRead = fs.Read(bytes, 0, bytes.Length)

            If bytesRead > 0 Then

                totalBytesRead += bytesRead

                'Write to stream
                s.Write(bytes, 0, bytesRead)

                'Update progress
                pb.Value = CInt(totalBytesRead \ 1024)

            End If

        Loop While bytesRead > 0

        s.Close()
        s.Dispose()
        s = Nothing

        fs.Close()
        fs.Dispose()
        fs = Nothing



        '*** THIS IS REALLY SLOW ***
        Dim response As HttpWebResponse = _
            DirectCast(request.GetResponse(), HttpWebResponse)


        'Check the ContentLength of the Response
        Dim code As HttpStatusCode = response.StatusCode

        response.Close()
        response = Nothing

        pb.Visible = False

        'Return Success
        Return (code = HttpStatusCode.OK)

    End Function
LVL 27
VBRocksAsked:
Who is Participating?
 
VBRocksConnect With a Mentor Author Commented:
I found the answer to this question, finally.  I disabled AllowWriteStreamBuffering.  However, it wasn't entirely as easy as that... but the following Microsoft Support article provided the tips to make it work:

     http://support.microsoft.com/kb/908573

0
 
thehagmanCommented:
The slow part is where the actual transmission occurs. Are you sure there is no bandwidth consumption happeneing at that stage?
Does using http instead of https speed things up?
0
 
VBRocksAuthor Commented:
Hi thehagman!  Thanks for taking a look at my post.

The site I'm accessing is a (WebDAV) secure transfer site (FTPES or HTTPS), so HTTP doesn't work, unfortunately.

As far as the bandwidth consumption...  I'm not really sure where to begin with that.  ?

Some of the research I've done has showed that computers are configured to download faster than upload, because the majority of data passed on the internet is being downloaded (such as webpages, images, files, etc.).

The upload code actually seems comparable to My.Computer.Network.UploadFile().
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.