<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Using HttpWebRequest for Asynchronous Downloads</title>
	<atom:link href="http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/feed/" rel="self" type="application/rss+xml" />
	<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/</link>
	<description>Learning new software development technologies out loud</description>
	<lastBuildDate>Sat, 21 Jan 2012 10:51:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: How to make Asynchronous Web requests in C# WPF &#124; FaceColony.org &#8211; Developers Network</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1800</link>
		<dc:creator><![CDATA[How to make Asynchronous Web requests in C# WPF &#124; FaceColony.org &#8211; Developers Network]]></dc:creator>
		<pubDate>Sat, 21 Jan 2012 10:51:46 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1800</guid>
		<description><![CDATA[[...] found this link but i am not sure how it is applicable to my problem. Any help or idea for how to go about [...]]]></description>
		<content:encoded><![CDATA[<p>[...] found this link but i am not sure how it is applicable to my problem. Any help or idea for how to go about [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1795</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Thu, 19 Jan 2012 20:24:14 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1795</guid>
		<description><![CDATA[I think pretty much anywhere you like--just as long as they&#039;re in scope for the code that uses the delegate type.]]></description>
		<content:encoded><![CDATA[<p>I think pretty much anywhere you like&#8211;just as long as they&#8217;re in scope for the code that uses the delegate type.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PEte</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1793</link>
		<dc:creator><![CDATA[PEte]]></dc:creator>
		<pubDate>Thu, 19 Jan 2012 18:03:11 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1793</guid>
		<description><![CDATA[I can&#039;t see where to place the delegate declarations.]]></description>
		<content:encoded><![CDATA[<p>I can&#8217;t see where to place the delegate declarations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Einar Jón</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1749</link>
		<dc:creator><![CDATA[Einar Jón]]></dc:creator>
		<pubDate>Fri, 30 Sep 2011 12:14:45 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1749</guid>
		<description><![CDATA[Very nice code, although the zip file is not available (your whole website seems to be out atm).

I save to a file by adding a FileStream variable to the WebRequestState, then initialize it with something like 
outFile = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
in the ctor and a 
reqState.outFile.Write(reqState.bufferRead, 0, bytesRead);
into the ReadCallback() function.

Works fine, even with doing multiple consecutive downloads (the labels and progress bar don&#039;t handle it, but that&#039;s easy to fix).]]></description>
		<content:encoded><![CDATA[<p>Very nice code, although the zip file is not available (your whole website seems to be out atm).</p>
<p>I save to a file by adding a FileStream variable to the WebRequestState, then initialize it with something like<br />
outFile = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);<br />
in the ctor and a<br />
reqState.outFile.Write(reqState.bufferRead, 0, bytesRead);<br />
into the ReadCallback() function.</p>
<p>Works fine, even with doing multiple consecutive downloads (the labels and progress bar don&#8217;t handle it, but that&#8217;s easy to fix).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1711</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Tue, 26 Jul 2011 20:44:15 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1711</guid>
		<description><![CDATA[De nada.  Writing C# code is almost as fulfilling as listening to Fado !]]></description>
		<content:encoded><![CDATA[<p>De nada.  Writing C# code is almost as fulfilling as listening to Fado !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruno de Carvalho</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1710</link>
		<dc:creator><![CDATA[Bruno de Carvalho]]></dc:creator>
		<pubDate>Tue, 26 Jul 2011 19:59:09 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1710</guid>
		<description><![CDATA[Hey Sean,


Thanks a lot for this article. It&#039;s been invaluable in understanding the shady depths of asynchronous execution of HttpWebRequest&#039;s in .NET.

Keep up the awesome work!


Cheers]]></description>
		<content:encoded><![CDATA[<p>Hey Sean,</p>
<p>Thanks a lot for this article. It&#8217;s been invaluable in understanding the shady depths of asynchronous execution of HttpWebRequest&#8217;s in .NET.</p>
<p>Keep up the awesome work!</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gal pasternak</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1696</link>
		<dc:creator><![CDATA[Gal pasternak]]></dc:creator>
		<pubDate>Mon, 09 May 2011 15:39:36 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1696</guid>
		<description><![CDATA[Is there any file size limitations with this implementation ?]]></description>
		<content:encoded><![CDATA[<p>Is there any file size limitations with this implementation ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1695</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Mon, 09 May 2011 14:49:38 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1695</guid>
		<description><![CDATA[Yes, you can certainly do file downloads (server-to-client) in ASP.NET.  If you want to do an asynchronous download, take a look at Jeff Prosise&#039;s article at http://msdn.microsoft.com/en-us/magazine/cc163725.aspx 

You might also look at this articles:
  http://www.codeproject.com/KB/aspnet/Download_Track.aspx

or take a look at the All-In-One Code Framework for ASP.NET, at:
  http://1code.codeplex.com/wikipage?title=ASP.NET]]></description>
		<content:encoded><![CDATA[<p>Yes, you can certainly do file downloads (server-to-client) in ASP.NET.  If you want to do an asynchronous download, take a look at Jeff Prosise&#8217;s article at <a href="http://msdn.microsoft.com/en-us/magazine/cc163725.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/cc163725.aspx</a> </p>
<p>You might also look at this articles:<br />
  <a href="http://www.codeproject.com/KB/aspnet/Download_Track.aspx" rel="nofollow">http://www.codeproject.com/KB/aspnet/Download_Track.aspx</a></p>
<p>or take a look at the All-In-One Code Framework for ASP.NET, at:<br />
  <a href="http://1code.codeplex.com/wikipage?title=ASP.NET" rel="nofollow">http://1code.codeplex.com/wikipage?title=ASP.NET</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gal pasternak</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1694</link>
		<dc:creator><![CDATA[Gal pasternak]]></dc:creator>
		<pubDate>Sun, 08 May 2011 21:01:38 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1694</guid>
		<description><![CDATA[Any way of implementing this with ASP.NET ?
I need to create an Asynchronous huge file download but it must be asp.net I cant install anything on the client. 

any help will be appreciated]]></description>
		<content:encoded><![CDATA[<p>Any way of implementing this with ASP.NET ?<br />
I need to create an Asynchronous huge file download but it must be asp.net I cant install anything on the client. </p>
<p>any help will be appreciated</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1620</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Wed, 06 Apr 2011 14:32:36 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1620</guid>
		<description><![CDATA[Uploading is pretty easy--just the reverse of downloading.  Instead of calling Stream.BeginRead, you call Stream.BeginWrite.  You can also specify a write callback, in the same way that you specified a read callback.  And the write callback would be where you&#039;d update your progress bar.  Doing the uploading, using all of my downloading code as an example, should be pretty easy--and a good way for you to learn what the code is doing. :O)]]></description>
		<content:encoded><![CDATA[<p>Uploading is pretty easy&#8211;just the reverse of downloading.  Instead of calling Stream.BeginRead, you call Stream.BeginWrite.  You can also specify a write callback, in the same way that you specified a read callback.  And the write callback would be where you&#8217;d update your progress bar.  Doing the uploading, using all of my downloading code as an example, should be pretty easy&#8211;and a good way for you to learn what the code is doing. :O)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sreejith K</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-1608</link>
		<dc:creator><![CDATA[Sreejith K]]></dc:creator>
		<pubDate>Wed, 06 Apr 2011 09:54:50 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-1608</guid>
		<description><![CDATA[Excellent code. I was trying to do the same when uploading files by POST. In this case, it looks like RespCallback is only called after the file has finished uploading.  Not sure how to show a progress bar in between. Can you please post an article about uploading as well?]]></description>
		<content:encoded><![CDATA[<p>Excellent code. I was trying to do the same when uploading files by POST. In this case, it looks like RespCallback is only called after the file has finished uploading.  Not sure how to show a progress bar in between. Can you please post an article about uploading as well?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-516</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Thu, 20 May 2010 16:42:06 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-516</guid>
		<description><![CDATA[I thanks for your code, now, I upload and download files in async mode in ftp with no problem...And update progress bar and more...

Only one problem, no send zip files...
Can you help-me? I send total bytes in ftp, but my file is damaged...more people have the same problem but any solutions...

   Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)
            Dim requestStream As Stream = reqState.streamResponse

            Dim stream As FileStream = reqState.filestreamup
            Dim bytesRead As Integer = stream.EndRead(asyncResult)


            If bytesRead &gt; 0 Then

                Dim buffer() As Byte = New Byte(bytesRead) {}
                requestStream.Write(buffer, 0, bytesRead)

                &#039; reqState.uploadfile(reqState.iforloop, bytesRead, False, reqState.bufferRead, requestStream)
                reqState.iforloop = CInt(reqState.iforloop + 1)
                &#039; Report some progress, including total # bytes read, % complete, and transfer rate
                reqState.bytesRead += bytesRead
                Dim pctComplete As Double = (CDbl(reqState.bytesRead) / CDbl(reqState.totalBytes)) * 100.0F
                &#039; Note: bytesRead/totalMS is in bytes/ms.  Convert to kb/sec.
                Dim totalTime As TimeSpan = DateTime.Now - reqState.transferStart
                Dim kbPerSec As Double = (reqState.bytesRead * 1000.0F) / (totalTime.TotalMilliseconds * 1024.0F)
                reqState.progCB(reqState.bytesRead, pctComplete, kbPerSec)
                &#039; Kick off another read

                Dim ar As IAsyncResult = stream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback1), reqState)

                Exit Sub
            Else

I you can help-me, I apologise....]]></description>
		<content:encoded><![CDATA[<p>I thanks for your code, now, I upload and download files in async mode in ftp with no problem&#8230;And update progress bar and more&#8230;</p>
<p>Only one problem, no send zip files&#8230;<br />
Can you help-me? I send total bytes in ftp, but my file is damaged&#8230;more people have the same problem but any solutions&#8230;</p>
<p>   Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)<br />
            Dim requestStream As Stream = reqState.streamResponse</p>
<p>            Dim stream As FileStream = reqState.filestreamup<br />
            Dim bytesRead As Integer = stream.EndRead(asyncResult)</p>
<p>            If bytesRead &gt; 0 Then</p>
<p>                Dim buffer() As Byte = New Byte(bytesRead) {}<br />
                requestStream.Write(buffer, 0, bytesRead)</p>
<p>                &#8216; reqState.uploadfile(reqState.iforloop, bytesRead, False, reqState.bufferRead, requestStream)<br />
                reqState.iforloop = CInt(reqState.iforloop + 1)<br />
                &#8216; Report some progress, including total # bytes read, % complete, and transfer rate<br />
                reqState.bytesRead += bytesRead<br />
                Dim pctComplete As Double = (CDbl(reqState.bytesRead) / CDbl(reqState.totalBytes)) * 100.0F<br />
                &#8216; Note: bytesRead/totalMS is in bytes/ms.  Convert to kb/sec.<br />
                Dim totalTime As TimeSpan = DateTime.Now &#8211; reqState.transferStart<br />
                Dim kbPerSec As Double = (reqState.bytesRead * 1000.0F) / (totalTime.TotalMilliseconds * 1024.0F)<br />
                reqState.progCB(reqState.bytesRead, pctComplete, kbPerSec)<br />
                &#8216; Kick off another read</p>
<p>                Dim ar As IAsyncResult = stream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback1), reqState)</p>
<p>                Exit Sub<br />
            Else</p>
<p>I you can help-me, I apologise&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-514</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Fri, 14 May 2010 11:39:21 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-514</guid>
		<description><![CDATA[http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx

In this link, have code for upload async, but the in true, the upload is not async because use do while...]]></description>
		<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx</a></p>
<p>In this link, have code for upload async, but the in true, the upload is not async because use do while&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-513</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Thu, 13 May 2010 23:12:39 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-513</guid>
		<description><![CDATA[Certantly my loop is incorrectly because my progress is very fast...]]></description>
		<content:encoded><![CDATA[<p>Certantly my loop is incorrectly because my progress is very fast&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-512</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Thu, 13 May 2010 22:25:44 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-512</guid>
		<description><![CDATA[With this sequence code, the loop is perfectly, progress bar ok but I dont know Hou can I write in ftp my file...

Here I think that is write file here...
 Private Sub teste1(ByVal lopps As Integer, ByVal bufer As Integer, ByVal valida As Boolean, ByVal bufferRead As Byte(), ByVal reqstated As FileStream)
        If Me.InvokeRequired Then
            Dim del As New teste1Delegate(AddressOf teste1)
            Me.Invoke(del, New Object() {lopps, bufer, valida, bufferRead, reqstated})
        Else
            Dim buffer As Byte() = New Byte(bufer) {}
            If lopps = &quot;0&quot; Then
                &#039; Dim FileStreamm As FileStream = File.Open(&quot;d:\rel1.xls&quot;, FileMode.Open)
                &#039;FileStreamm.Write(bufferRead, 0, bufer)
            Else
                If valida = True Then
                    &#039; FileStreamm.Close()
                Else
                    &#039;  FileStreamm.Write(bufferRead, 0, bufer)
                End If
            End If
        End If
    End Sub

Here, I get de file size and pass ithis to reqstate.toltalbytes...

    Private Sub sendfile()
        Try

            conecte.Text = &quot;Conectado...&quot;
            lblDownloadComplete.Visible = False
            Dim req As WebRequest = Nothing
            Dim reqState As WebRequestState = Nothing
            &#039;Dim buffer As Byte() = New Byte(1448) {}
            reqState = New FtpWebRequestState(BUFFER_SIZE)
            Dim fileURI As New Uri(txtURI.Text &amp; &quot;/&quot; &amp; TextBox2.Text)
            req = DirectCast(FtpWebRequest.Create(fileURI), FtpWebRequest)
            req.Credentials = New NetworkCredential(campousuario.Text, camposenha.Text)
            DirectCast(req, FtpWebRequest).KeepAlive = False
            DirectCast(req, FtpWebRequest).Method = WebRequestMethods.Ftp.UploadFile
            reqState.FTPMethod = WebRequestMethods.Ftp.UploadFile

            Dim FileStreamm As FileStream = File.Open(&quot;d:\rel1.xls&quot;, FileMode.Open)
            reqState.totalBytes = FileStreamm.Length
            reqState.streamResponse = FileStreamm
           


            If req IsNot Nothing Then
                reqState.fileURI = fileURI
                reqState.respInfoCB = New ResponseInfoDelegate(AddressOf SetResponseInfo)
                reqState.progCB = New ProgressDelegate(AddressOf Progress)
                reqState.doneCB = New DoneDelegate(AddressOf Done)
                reqState.getlist1 = New teste1Delegate(AddressOf teste1)
                reqState.transferStart = DateTime.Now

                reqState.request = req

                Dim result As IAsyncResult = DirectCast(req.BeginGetResponse(New AsyncCallback(AddressOf ReadCallback1), reqState), IAsyncResult)


                &#039; Start the asynchronous request.

                &#039;   End If

                &#039; While True
                &#039;   bytesread = FileStream.Read(buffer, 0, buffer.Length)
                &#039;    MsgBox(bytesread.ToString)
                &#039;  If bytesread = 0 Then
                &#039;Exit While
                &#039;   Else
                &#039;  requestStream.Write(buffer, 0, bytesread)
            End If
            &#039;   End While
        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in button1_Click(): {0}&quot;, ex.Message))
        End Try
    End Sub

Here I get the first bytes of file...
    Public Shared Sub ReadCallback1(ByVal asyncResult As IAsyncResult)
        Try
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)
            Dim req As WebRequest = reqState.request
            Dim statusDescr As String = &quot;&quot;
            Dim contentLength As String = &quot;&quot;


            &#039; Dim FileStreamm As FileStream = File.Open(&quot;d:\rel1.xls&quot;, FileMode.Open)

            Dim resp As FtpWebResponse = DirectCast((req.EndGetResponse(asyncResult)), FtpWebResponse)
            reqState.response = resp


            statusDescr = resp.StatusDescription
            &#039; reqState.totalBytes = FileStreamm.Length
            &#039; # bytes
            contentLength = reqState.totalBytes

            &#039; Get this info back to the GUI -- max # bytes, so we can do progress bar
            If statusDescr  &quot;&quot; Then

                reqState.respInfoCB(statusDescr, contentLength)
            End If

            &#039; Dim responseStream As Stream = FileStreamm
            Dim responseStream As Stream = reqState.streamResponse
            reqState.streamResponse = responseStream


            &#039; Begin reading contents of the response data

            Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)
        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in ReadCallback(): {0}&quot;, ex.Message))
        End Try
    End Sub
 And here I make a loop...call the teste1 fo write file...
How Can I finish this code for finaly write in ftp?

    Public Shared Sub ReadCallback2(ByVal asyncResult As IAsyncResult)

        Try
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)
            Dim responseStream As Stream = reqState.streamResponse
            &#039; Get results of read operation
            Dim bytesRead As Integer = responseStream.EndRead(asyncResult)

            Dim buffer As Byte() = New Byte(bytesRead) {}

            reqState.getlist1(reqState.iforloop, bytesRead, False, reqState.bufferRead, reqState.streamResponse)
            reqState.iforloop = CInt(reqState.iforloop + 1)
            &#039; Got some data, need to read more
            If bytesRead &gt; 0 Then
                &#039; Report some progress, including total # bytes read, % complete, and transfer rate
                reqState.bytesRead += bytesRead
                Dim pctComplete As Double = (CDbl(reqState.bytesRead) / CDbl(reqState.totalBytes)) * 100.0F
                &#039; Note: bytesRead/totalMS is in bytes/ms.  Convert to kb/sec.
                Dim totalTime As TimeSpan = DateTime.Now - reqState.transferStart
                Dim kbPerSec As Double = (reqState.bytesRead * 1000.0F) / (totalTime.TotalMilliseconds * 1024.0F)
                reqState.progCB(reqState.bytesRead, pctComplete, kbPerSec)
                &#039; Kick off another read
                Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)
                Exit Sub
            Else
                MsgBox(&quot;dentro do else&quot;)
                reqState.getlist1(reqState.iforloop, bytesRead, True, reqState.bufferRead, reqState.streamResponse)
                &#039;Dim ms As FileStream = New FileStream(&quot;d:\testestream.doc&quot;, FileMode.Create)
                &#039; ms.Write(reqState.bufferRead, 0, BUFFER_SIZE)
                &#039; reqState.getlist(reqState.iforloop, bytesRead, True, reqState.bufferRead)
                &#039;   responseStream.Write(, 0, BUFFER_SIZE)
                &#039;memStream.Close()

                &#039; EndRead returned 0, so no more data to be read
                responseStream.Close()
                reqState.response.Close()
                reqState.doneCB()
            End If


        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in ReadCallback(): {0}&quot;, ex.Message))
        End Try
    End Sub]]></description>
		<content:encoded><![CDATA[<p>With this sequence code, the loop is perfectly, progress bar ok but I dont know Hou can I write in ftp my file&#8230;</p>
<p>Here I think that is write file here&#8230;<br />
 Private Sub teste1(ByVal lopps As Integer, ByVal bufer As Integer, ByVal valida As Boolean, ByVal bufferRead As Byte(), ByVal reqstated As FileStream)<br />
        If Me.InvokeRequired Then<br />
            Dim del As New teste1Delegate(AddressOf teste1)<br />
            Me.Invoke(del, New Object() {lopps, bufer, valida, bufferRead, reqstated})<br />
        Else<br />
            Dim buffer As Byte() = New Byte(bufer) {}<br />
            If lopps = &#8220;0&#8243; Then<br />
                &#8216; Dim FileStreamm As FileStream = File.Open(&#8220;d:\rel1.xls&#8221;, FileMode.Open)<br />
                &#8216;FileStreamm.Write(bufferRead, 0, bufer)<br />
            Else<br />
                If valida = True Then<br />
                    &#8216; FileStreamm.Close()<br />
                Else<br />
                    &#8216;  FileStreamm.Write(bufferRead, 0, bufer)<br />
                End If<br />
            End If<br />
        End If<br />
    End Sub</p>
<p>Here, I get de file size and pass ithis to reqstate.toltalbytes&#8230;</p>
<p>    Private Sub sendfile()<br />
        Try</p>
<p>            conecte.Text = &#8220;Conectado&#8230;&#8221;<br />
            lblDownloadComplete.Visible = False<br />
            Dim req As WebRequest = Nothing<br />
            Dim reqState As WebRequestState = Nothing<br />
            &#8216;Dim buffer As Byte() = New Byte(1448) {}<br />
            reqState = New FtpWebRequestState(BUFFER_SIZE)<br />
            Dim fileURI As New Uri(txtURI.Text &amp; &#8220;/&#8221; &amp; TextBox2.Text)<br />
            req = DirectCast(FtpWebRequest.Create(fileURI), FtpWebRequest)<br />
            req.Credentials = New NetworkCredential(campousuario.Text, camposenha.Text)<br />
            DirectCast(req, FtpWebRequest).KeepAlive = False<br />
            DirectCast(req, FtpWebRequest).Method = WebRequestMethods.Ftp.UploadFile<br />
            reqState.FTPMethod = WebRequestMethods.Ftp.UploadFile</p>
<p>            Dim FileStreamm As FileStream = File.Open(&#8220;d:\rel1.xls&#8221;, FileMode.Open)<br />
            reqState.totalBytes = FileStreamm.Length<br />
            reqState.streamResponse = FileStreamm</p>
<p>            If req IsNot Nothing Then<br />
                reqState.fileURI = fileURI<br />
                reqState.respInfoCB = New ResponseInfoDelegate(AddressOf SetResponseInfo)<br />
                reqState.progCB = New ProgressDelegate(AddressOf Progress)<br />
                reqState.doneCB = New DoneDelegate(AddressOf Done)<br />
                reqState.getlist1 = New teste1Delegate(AddressOf teste1)<br />
                reqState.transferStart = DateTime.Now</p>
<p>                reqState.request = req</p>
<p>                Dim result As IAsyncResult = DirectCast(req.BeginGetResponse(New AsyncCallback(AddressOf ReadCallback1), reqState), IAsyncResult)</p>
<p>                &#8216; Start the asynchronous request.</p>
<p>                &#8216;   End If</p>
<p>                &#8216; While True<br />
                &#8216;   bytesread = FileStream.Read(buffer, 0, buffer.Length)<br />
                &#8216;    MsgBox(bytesread.ToString)<br />
                &#8216;  If bytesread = 0 Then<br />
                &#8216;Exit While<br />
                &#8216;   Else<br />
                &#8216;  requestStream.Write(buffer, 0, bytesread)<br />
            End If<br />
            &#8216;   End While<br />
        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in button1_Click(): {0}&#8221;, ex.Message))<br />
        End Try<br />
    End Sub</p>
<p>Here I get the first bytes of file&#8230;<br />
    Public Shared Sub ReadCallback1(ByVal asyncResult As IAsyncResult)<br />
        Try<br />
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)<br />
            Dim req As WebRequest = reqState.request<br />
            Dim statusDescr As String = &#8220;&#8221;<br />
            Dim contentLength As String = &#8220;&#8221;</p>
<p>            &#8216; Dim FileStreamm As FileStream = File.Open(&#8220;d:\rel1.xls&#8221;, FileMode.Open)</p>
<p>            Dim resp As FtpWebResponse = DirectCast((req.EndGetResponse(asyncResult)), FtpWebResponse)<br />
            reqState.response = resp</p>
<p>            statusDescr = resp.StatusDescription<br />
            &#8216; reqState.totalBytes = FileStreamm.Length<br />
            &#8216; # bytes<br />
            contentLength = reqState.totalBytes</p>
<p>            &#8216; Get this info back to the GUI &#8212; max # bytes, so we can do progress bar<br />
            If statusDescr  &#8220;&#8221; Then</p>
<p>                reqState.respInfoCB(statusDescr, contentLength)<br />
            End If</p>
<p>            &#8216; Dim responseStream As Stream = FileStreamm<br />
            Dim responseStream As Stream = reqState.streamResponse<br />
            reqState.streamResponse = responseStream</p>
<p>            &#8216; Begin reading contents of the response data</p>
<p>            Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)<br />
        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in ReadCallback(): {0}&#8221;, ex.Message))<br />
        End Try<br />
    End Sub<br />
 And here I make a loop&#8230;call the teste1 fo write file&#8230;<br />
How Can I finish this code for finaly write in ftp?</p>
<p>    Public Shared Sub ReadCallback2(ByVal asyncResult As IAsyncResult)</p>
<p>        Try<br />
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)<br />
            Dim responseStream As Stream = reqState.streamResponse<br />
            &#8216; Get results of read operation<br />
            Dim bytesRead As Integer = responseStream.EndRead(asyncResult)</p>
<p>            Dim buffer As Byte() = New Byte(bytesRead) {}</p>
<p>            reqState.getlist1(reqState.iforloop, bytesRead, False, reqState.bufferRead, reqState.streamResponse)<br />
            reqState.iforloop = CInt(reqState.iforloop + 1)<br />
            &#8216; Got some data, need to read more<br />
            If bytesRead &gt; 0 Then<br />
                &#8216; Report some progress, including total # bytes read, % complete, and transfer rate<br />
                reqState.bytesRead += bytesRead<br />
                Dim pctComplete As Double = (CDbl(reqState.bytesRead) / CDbl(reqState.totalBytes)) * 100.0F<br />
                &#8216; Note: bytesRead/totalMS is in bytes/ms.  Convert to kb/sec.<br />
                Dim totalTime As TimeSpan = DateTime.Now &#8211; reqState.transferStart<br />
                Dim kbPerSec As Double = (reqState.bytesRead * 1000.0F) / (totalTime.TotalMilliseconds * 1024.0F)<br />
                reqState.progCB(reqState.bytesRead, pctComplete, kbPerSec)<br />
                &#8216; Kick off another read<br />
                Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)<br />
                Exit Sub<br />
            Else<br />
                MsgBox(&#8220;dentro do else&#8221;)<br />
                reqState.getlist1(reqState.iforloop, bytesRead, True, reqState.bufferRead, reqState.streamResponse)<br />
                &#8216;Dim ms As FileStream = New FileStream(&#8220;d:\testestream.doc&#8221;, FileMode.Create)<br />
                &#8216; ms.Write(reqState.bufferRead, 0, BUFFER_SIZE)<br />
                &#8216; reqState.getlist(reqState.iforloop, bytesRead, True, reqState.bufferRead)<br />
                &#8216;   responseStream.Write(, 0, BUFFER_SIZE)<br />
                &#8216;memStream.Close()</p>
<p>                &#8216; EndRead returned 0, so no more data to be read<br />
                responseStream.Close()<br />
                reqState.response.Close()<br />
                reqState.doneCB()<br />
            End If</p>
<p>        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in ReadCallback(): {0}&#8221;, ex.Message))<br />
        End Try<br />
    End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-511</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Thu, 13 May 2010 22:25:13 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-511</guid>
		<description><![CDATA[With this sequence code, the loop is perfectly, progress bar ok but I dont know Hou can I write in ftp my file...

Here I think that is write file here...
 Private Sub teste1(ByVal lopps As Integer, ByVal bufer As Integer, ByVal valida As Boolean, ByVal bufferRead As Byte(), ByVal reqstated As FileStream)
        If Me.InvokeRequired Then
            Dim del As New teste1Delegate(AddressOf teste1)
            Me.Invoke(del, New Object() {lopps, bufer, valida, bufferRead, reqstated})
        Else
            Dim buffer As Byte() = New Byte(bufer) {}
            If lopps = &quot;0&quot; Then
                &#039; Dim FileStreamm As FileStream = File.Open(&quot;d:\rel1.xls&quot;, FileMode.Open)
                &#039;FileStreamm.Write(bufferRead, 0, bufer)
            Else
                If valida = True Then
                    &#039; FileStreamm.Close()
                Else
                    &#039;  FileStreamm.Write(bufferRead, 0, bufer)
                End If
            End If
        End If
    End Sub

Here, I get de file size and pass ithis to reqstate.toltalbytes...

    Private Sub sendfile()
        Try

            conecte.Text = &quot;Conectado...&quot;
            lblDownloadComplete.Visible = False
            Dim req As WebRequest = Nothing
            Dim reqState As WebRequestState = Nothing
            &#039;Dim buffer As Byte() = New Byte(1448) {}
            reqState = New FtpWebRequestState(BUFFER_SIZE)
            Dim fileURI As New Uri(txtURI.Text &amp; &quot;/&quot; &amp; TextBox2.Text)
            req = DirectCast(FtpWebRequest.Create(fileURI), FtpWebRequest)
            req.Credentials = New NetworkCredential(campousuario.Text, camposenha.Text)
            DirectCast(req, FtpWebRequest).KeepAlive = False
            DirectCast(req, FtpWebRequest).Method = WebRequestMethods.Ftp.UploadFile
            reqState.FTPMethod = WebRequestMethods.Ftp.UploadFile

            Dim FileStreamm As FileStream = File.Open(&quot;d:\rel1.xls&quot;, FileMode.Open)
            reqState.totalBytes = FileStreamm.Length
            reqState.streamResponse = FileStreamm
           


            If req IsNot Nothing Then
                reqState.fileURI = fileURI
                reqState.respInfoCB = New ResponseInfoDelegate(AddressOf SetResponseInfo)
                reqState.progCB = New ProgressDelegate(AddressOf Progress)
                reqState.doneCB = New DoneDelegate(AddressOf Done)
                reqState.getlist1 = New teste1Delegate(AddressOf teste1)
                reqState.transferStart = DateTime.Now

                reqState.request = req

                Dim result As IAsyncResult = DirectCast(req.BeginGetResponse(New AsyncCallback(AddressOf ReadCallback1), reqState), IAsyncResult)


                &#039; Start the asynchronous request.

                &#039;   End If

                &#039; While True
                &#039;   bytesread = FileStream.Read(buffer, 0, buffer.Length)
                &#039;    MsgBox(bytesread.ToString)
                &#039;  If bytesread = 0 Then
                &#039;Exit While
                &#039;   Else
                &#039;  requestStream.Write(buffer, 0, bytesread)
            End If
            &#039;   End While
        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in button1_Click(): {0}&quot;, ex.Message))
        End Try
    End Sub

Here I get the first bytes of file...
    Public Shared Sub ReadCallback1(ByVal asyncResult As IAsyncResult)
        Try
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)
            Dim req As WebRequest = reqState.request
            Dim statusDescr As String = &quot;&quot;
            Dim contentLength As String = &quot;&quot;


            &#039; Dim FileStreamm As FileStream = File.Open(&quot;d:\rel1.xls&quot;, FileMode.Open)

            Dim resp As FtpWebResponse = DirectCast((req.EndGetResponse(asyncResult)), FtpWebResponse)
            reqState.response = resp


            statusDescr = resp.StatusDescription
            &#039; reqState.totalBytes = FileStreamm.Length
            &#039; # bytes
            contentLength = reqState.totalBytes

            &#039; Get this info back to the GUI -- max # bytes, so we can do progress bar
            If statusDescr  &quot;&quot; Then

                reqState.respInfoCB(statusDescr, contentLength)
            End If

            &#039; Dim responseStream As Stream = FileStreamm
            Dim responseStream As Stream = reqState.streamResponse
            reqState.streamResponse = responseStream


            &#039; Begin reading contents of the response data

            Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)
        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in ReadCallback(): {0}&quot;, ex.Message))
        End Try
    End Sub
 And here I make a loop...call the teste1 fo write file...
How Can I finish this code for finaly write in ftp?]]></description>
		<content:encoded><![CDATA[<p>With this sequence code, the loop is perfectly, progress bar ok but I dont know Hou can I write in ftp my file&#8230;</p>
<p>Here I think that is write file here&#8230;<br />
 Private Sub teste1(ByVal lopps As Integer, ByVal bufer As Integer, ByVal valida As Boolean, ByVal bufferRead As Byte(), ByVal reqstated As FileStream)<br />
        If Me.InvokeRequired Then<br />
            Dim del As New teste1Delegate(AddressOf teste1)<br />
            Me.Invoke(del, New Object() {lopps, bufer, valida, bufferRead, reqstated})<br />
        Else<br />
            Dim buffer As Byte() = New Byte(bufer) {}<br />
            If lopps = &#8220;0&#8243; Then<br />
                &#8216; Dim FileStreamm As FileStream = File.Open(&#8220;d:\rel1.xls&#8221;, FileMode.Open)<br />
                &#8216;FileStreamm.Write(bufferRead, 0, bufer)<br />
            Else<br />
                If valida = True Then<br />
                    &#8216; FileStreamm.Close()<br />
                Else<br />
                    &#8216;  FileStreamm.Write(bufferRead, 0, bufer)<br />
                End If<br />
            End If<br />
        End If<br />
    End Sub</p>
<p>Here, I get de file size and pass ithis to reqstate.toltalbytes&#8230;</p>
<p>    Private Sub sendfile()<br />
        Try</p>
<p>            conecte.Text = &#8220;Conectado&#8230;&#8221;<br />
            lblDownloadComplete.Visible = False<br />
            Dim req As WebRequest = Nothing<br />
            Dim reqState As WebRequestState = Nothing<br />
            &#8216;Dim buffer As Byte() = New Byte(1448) {}<br />
            reqState = New FtpWebRequestState(BUFFER_SIZE)<br />
            Dim fileURI As New Uri(txtURI.Text &amp; &#8220;/&#8221; &amp; TextBox2.Text)<br />
            req = DirectCast(FtpWebRequest.Create(fileURI), FtpWebRequest)<br />
            req.Credentials = New NetworkCredential(campousuario.Text, camposenha.Text)<br />
            DirectCast(req, FtpWebRequest).KeepAlive = False<br />
            DirectCast(req, FtpWebRequest).Method = WebRequestMethods.Ftp.UploadFile<br />
            reqState.FTPMethod = WebRequestMethods.Ftp.UploadFile</p>
<p>            Dim FileStreamm As FileStream = File.Open(&#8220;d:\rel1.xls&#8221;, FileMode.Open)<br />
            reqState.totalBytes = FileStreamm.Length<br />
            reqState.streamResponse = FileStreamm</p>
<p>            If req IsNot Nothing Then<br />
                reqState.fileURI = fileURI<br />
                reqState.respInfoCB = New ResponseInfoDelegate(AddressOf SetResponseInfo)<br />
                reqState.progCB = New ProgressDelegate(AddressOf Progress)<br />
                reqState.doneCB = New DoneDelegate(AddressOf Done)<br />
                reqState.getlist1 = New teste1Delegate(AddressOf teste1)<br />
                reqState.transferStart = DateTime.Now</p>
<p>                reqState.request = req</p>
<p>                Dim result As IAsyncResult = DirectCast(req.BeginGetResponse(New AsyncCallback(AddressOf ReadCallback1), reqState), IAsyncResult)</p>
<p>                &#8216; Start the asynchronous request.</p>
<p>                &#8216;   End If</p>
<p>                &#8216; While True<br />
                &#8216;   bytesread = FileStream.Read(buffer, 0, buffer.Length)<br />
                &#8216;    MsgBox(bytesread.ToString)<br />
                &#8216;  If bytesread = 0 Then<br />
                &#8216;Exit While<br />
                &#8216;   Else<br />
                &#8216;  requestStream.Write(buffer, 0, bytesread)<br />
            End If<br />
            &#8216;   End While<br />
        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in button1_Click(): {0}&#8221;, ex.Message))<br />
        End Try<br />
    End Sub</p>
<p>Here I get the first bytes of file&#8230;<br />
    Public Shared Sub ReadCallback1(ByVal asyncResult As IAsyncResult)<br />
        Try<br />
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)<br />
            Dim req As WebRequest = reqState.request<br />
            Dim statusDescr As String = &#8220;&#8221;<br />
            Dim contentLength As String = &#8220;&#8221;</p>
<p>            &#8216; Dim FileStreamm As FileStream = File.Open(&#8220;d:\rel1.xls&#8221;, FileMode.Open)</p>
<p>            Dim resp As FtpWebResponse = DirectCast((req.EndGetResponse(asyncResult)), FtpWebResponse)<br />
            reqState.response = resp</p>
<p>            statusDescr = resp.StatusDescription<br />
            &#8216; reqState.totalBytes = FileStreamm.Length<br />
            &#8216; # bytes<br />
            contentLength = reqState.totalBytes</p>
<p>            &#8216; Get this info back to the GUI &#8212; max # bytes, so we can do progress bar<br />
            If statusDescr  &#8220;&#8221; Then</p>
<p>                reqState.respInfoCB(statusDescr, contentLength)<br />
            End If</p>
<p>            &#8216; Dim responseStream As Stream = FileStreamm<br />
            Dim responseStream As Stream = reqState.streamResponse<br />
            reqState.streamResponse = responseStream</p>
<p>            &#8216; Begin reading contents of the response data</p>
<p>            Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)<br />
        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in ReadCallback(): {0}&#8221;, ex.Message))<br />
        End Try<br />
    End Sub<br />
 And here I make a loop&#8230;call the teste1 fo write file&#8230;<br />
How Can I finish this code for finaly write in ftp?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-510</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Wed, 12 May 2010 22:39:05 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-510</guid>
		<description><![CDATA[With this sequence code, I make loop, and progress bar ok...I write the file in ftp, but wiyh size 0.

 Private Sub sendfile()
        Try

            conecte.Text = &quot;Conectado...&quot;
            lblDownloadComplete.Visible = False
            Dim req As WebRequest = Nothing
            Dim reqState As WebRequestState = Nothing
            &#039;Dim buffer As Byte() = New Byte(1448) {}
            reqState = New FtpWebRequestState(BUFFER_SIZE)
            Dim fileURI As New Uri(txtURI.Text &amp; &quot;/&quot; &amp; TextBox2.Text)
            req = DirectCast(FtpWebRequest.Create(fileURI), FtpWebRequest)
            req.Credentials = New NetworkCredential(campousuario.Text, camposenha.Text)
            DirectCast(req, FtpWebRequest).KeepAlive = False
            DirectCast(req, FtpWebRequest).Method = WebRequestMethods.Ftp.UploadFile
            reqState.FTPMethod = WebRequestMethods.Ftp.UploadFile


            If req IsNot Nothing Then
                reqState.fileURI = fileURI
                reqState.respInfoCB = New ResponseInfoDelegate(AddressOf SetResponseInfo)
                reqState.progCB = New ProgressDelegate(AddressOf Progress)
                reqState.doneCB = New DoneDelegate(AddressOf Done)
                &#039; reqState.getlist = New testeDelegate(AddressOf teste)
                reqState.transferStart = DateTime.Now

                reqState.request = req

                Dim result As IAsyncResult = DirectCast(req.BeginGetResponse(New AsyncCallback(AddressOf ReadCallback1), reqState), IAsyncResult)


                &#039; Start the asynchronous request.

                &#039;   End If

                &#039; While True
                &#039;   bytesread = FileStream.Read(buffer, 0, buffer.Length)
                &#039;    MsgBox(bytesread.ToString)
                &#039;  If bytesread = 0 Then
                &#039;Exit While
                &#039;   Else
                &#039;  requestStream.Write(buffer, 0, bytesread)
            End If
            &#039;   End While
        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in button1_Click(): {0}&quot;, ex.Message))
        End Try
    End Sub




    Public Shared Sub ReadCallback1(ByVal asyncResult As IAsyncResult)
        Try
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)
            Dim req As WebRequest = reqState.request
            Dim statusDescr As String = &quot;&quot;
            Dim contentLength As String = &quot;&quot;


            Dim FileStreamm As FileStream = File.Open(&quot;d:\rel1.xls&quot;, FileMode.Open)

            Dim resp As FtpWebResponse = DirectCast((req.EndGetResponse(asyncResult)), FtpWebResponse)
            reqState.response = resp


            statusDescr = resp.StatusDescription
            reqState.totalBytes = FileStreamm.Length
            &#039; # bytes
            contentLength = reqState.totalBytes

            &#039; Get this info back to the GUI -- max # bytes, so we can do progress bar
            If statusDescr  &quot;&quot; Then

                reqState.respInfoCB(statusDescr, contentLength)
            End If

            Dim responseStream As Stream = FileStreamm
            reqState.streamResponse = responseStream

            &#039; Begin reading contents of the response data

            Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)
        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in ReadCallback(): {0}&quot;, ex.Message))
        End Try
    End Sub
    Public Shared Sub ReadCallback2(ByVal asyncResult As IAsyncResult)

        Try
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)
            Dim responseStream As Stream = reqState.streamResponse
            &#039; Get results of read operation
            Dim bytesRead As Integer = responseStream.EndRead(asyncResult)

            Dim buffer As Byte() = New Byte(bytesRead) {}
            responseStream.Write(buffer, 0, bytesRead)


            &#039; Got some data, need to read more
            If bytesRead &gt; 0 Then
                &#039; Report some progress, including total # bytes read, % complete, and transfer rate
                reqState.bytesRead += bytesRead
                Dim pctComplete As Double = (CDbl(reqState.bytesRead) / CDbl(reqState.totalBytes)) * 100.0F
                &#039; Note: bytesRead/totalMS is in bytes/ms.  Convert to kb/sec.
                Dim totalTime As TimeSpan = DateTime.Now - reqState.transferStart
                Dim kbPerSec As Double = (reqState.bytesRead * 1000.0F) / (totalTime.TotalMilliseconds * 1024.0F)
                reqState.progCB(reqState.bytesRead, pctComplete, kbPerSec)
                &#039; Kick off another read
                Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)
                Exit Sub
            Else
                MsgBox(&quot;dentro do else&quot;)
                &#039;Dim ms As FileStream = New FileStream(&quot;d:\testestream.doc&quot;, FileMode.Create)
                &#039; ms.Write(reqState.bufferRead, 0, BUFFER_SIZE)
                &#039; reqState.getlist(reqState.iforloop, bytesRead, True, reqState.bufferRead)
                &#039;   responseStream.Write(, 0, BUFFER_SIZE)
                &#039;memStream.Close()

                &#039; EndRead returned 0, so no more data to be read
                responseStream.Close()
                reqState.response.Close()
                reqState.doneCB()
            End If


        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in ReadCallback(): {0}&quot;, ex.Message))
        End Try
    End Sub]]></description>
		<content:encoded><![CDATA[<p>With this sequence code, I make loop, and progress bar ok&#8230;I write the file in ftp, but wiyh size 0.</p>
<p> Private Sub sendfile()<br />
        Try</p>
<p>            conecte.Text = &#8220;Conectado&#8230;&#8221;<br />
            lblDownloadComplete.Visible = False<br />
            Dim req As WebRequest = Nothing<br />
            Dim reqState As WebRequestState = Nothing<br />
            &#8216;Dim buffer As Byte() = New Byte(1448) {}<br />
            reqState = New FtpWebRequestState(BUFFER_SIZE)<br />
            Dim fileURI As New Uri(txtURI.Text &amp; &#8220;/&#8221; &amp; TextBox2.Text)<br />
            req = DirectCast(FtpWebRequest.Create(fileURI), FtpWebRequest)<br />
            req.Credentials = New NetworkCredential(campousuario.Text, camposenha.Text)<br />
            DirectCast(req, FtpWebRequest).KeepAlive = False<br />
            DirectCast(req, FtpWebRequest).Method = WebRequestMethods.Ftp.UploadFile<br />
            reqState.FTPMethod = WebRequestMethods.Ftp.UploadFile</p>
<p>            If req IsNot Nothing Then<br />
                reqState.fileURI = fileURI<br />
                reqState.respInfoCB = New ResponseInfoDelegate(AddressOf SetResponseInfo)<br />
                reqState.progCB = New ProgressDelegate(AddressOf Progress)<br />
                reqState.doneCB = New DoneDelegate(AddressOf Done)<br />
                &#8216; reqState.getlist = New testeDelegate(AddressOf teste)<br />
                reqState.transferStart = DateTime.Now</p>
<p>                reqState.request = req</p>
<p>                Dim result As IAsyncResult = DirectCast(req.BeginGetResponse(New AsyncCallback(AddressOf ReadCallback1), reqState), IAsyncResult)</p>
<p>                &#8216; Start the asynchronous request.</p>
<p>                &#8216;   End If</p>
<p>                &#8216; While True<br />
                &#8216;   bytesread = FileStream.Read(buffer, 0, buffer.Length)<br />
                &#8216;    MsgBox(bytesread.ToString)<br />
                &#8216;  If bytesread = 0 Then<br />
                &#8216;Exit While<br />
                &#8216;   Else<br />
                &#8216;  requestStream.Write(buffer, 0, bytesread)<br />
            End If<br />
            &#8216;   End While<br />
        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in button1_Click(): {0}&#8221;, ex.Message))<br />
        End Try<br />
    End Sub</p>
<p>    Public Shared Sub ReadCallback1(ByVal asyncResult As IAsyncResult)<br />
        Try<br />
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)<br />
            Dim req As WebRequest = reqState.request<br />
            Dim statusDescr As String = &#8220;&#8221;<br />
            Dim contentLength As String = &#8220;&#8221;</p>
<p>            Dim FileStreamm As FileStream = File.Open(&#8220;d:\rel1.xls&#8221;, FileMode.Open)</p>
<p>            Dim resp As FtpWebResponse = DirectCast((req.EndGetResponse(asyncResult)), FtpWebResponse)<br />
            reqState.response = resp</p>
<p>            statusDescr = resp.StatusDescription<br />
            reqState.totalBytes = FileStreamm.Length<br />
            &#8216; # bytes<br />
            contentLength = reqState.totalBytes</p>
<p>            &#8216; Get this info back to the GUI &#8212; max # bytes, so we can do progress bar<br />
            If statusDescr  &#8220;&#8221; Then</p>
<p>                reqState.respInfoCB(statusDescr, contentLength)<br />
            End If</p>
<p>            Dim responseStream As Stream = FileStreamm<br />
            reqState.streamResponse = responseStream</p>
<p>            &#8216; Begin reading contents of the response data</p>
<p>            Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)<br />
        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in ReadCallback(): {0}&#8221;, ex.Message))<br />
        End Try<br />
    End Sub<br />
    Public Shared Sub ReadCallback2(ByVal asyncResult As IAsyncResult)</p>
<p>        Try<br />
            Dim reqState As WebRequestState = DirectCast((asyncResult.AsyncState), WebRequestState)<br />
            Dim responseStream As Stream = reqState.streamResponse<br />
            &#8216; Get results of read operation<br />
            Dim bytesRead As Integer = responseStream.EndRead(asyncResult)</p>
<p>            Dim buffer As Byte() = New Byte(bytesRead) {}<br />
            responseStream.Write(buffer, 0, bytesRead)</p>
<p>            &#8216; Got some data, need to read more<br />
            If bytesRead &gt; 0 Then<br />
                &#8216; Report some progress, including total # bytes read, % complete, and transfer rate<br />
                reqState.bytesRead += bytesRead<br />
                Dim pctComplete As Double = (CDbl(reqState.bytesRead) / CDbl(reqState.totalBytes)) * 100.0F<br />
                &#8216; Note: bytesRead/totalMS is in bytes/ms.  Convert to kb/sec.<br />
                Dim totalTime As TimeSpan = DateTime.Now &#8211; reqState.transferStart<br />
                Dim kbPerSec As Double = (reqState.bytesRead * 1000.0F) / (totalTime.TotalMilliseconds * 1024.0F)<br />
                reqState.progCB(reqState.bytesRead, pctComplete, kbPerSec)<br />
                &#8216; Kick off another read<br />
                Dim ar As IAsyncResult = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, New AsyncCallback(AddressOf ReadCallback2), reqState)<br />
                Exit Sub<br />
            Else<br />
                MsgBox(&#8220;dentro do else&#8221;)<br />
                &#8216;Dim ms As FileStream = New FileStream(&#8220;d:\testestream.doc&#8221;, FileMode.Create)<br />
                &#8216; ms.Write(reqState.bufferRead, 0, BUFFER_SIZE)<br />
                &#8216; reqState.getlist(reqState.iforloop, bytesRead, True, reqState.bufferRead)<br />
                &#8216;   responseStream.Write(, 0, BUFFER_SIZE)<br />
                &#8216;memStream.Close()</p>
<p>                &#8216; EndRead returned 0, so no more data to be read<br />
                responseStream.Close()<br />
                reqState.response.Close()<br />
                reqState.doneCB()<br />
            End If</p>
<p>        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in ReadCallback(): {0}&#8221;, ex.Message))<br />
        End Try<br />
    End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-505</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Tue, 11 May 2010 18:07:05 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-505</guid>
		<description><![CDATA[Try
            Dim req As WebRequest = Nothing
            Dim fileURI As New Uri(txtURI.Text &amp; &quot;/&quot; &amp; TextBox2.Text)
            req = DirectCast(FtpWebRequest.Create(fileURI), FtpWebRequest)
            req.Credentials = New NetworkCredential(campousuario.Text, camposenha.Text)
            DirectCast(req, FtpWebRequest).KeepAlive = False
            DirectCast(req, FtpWebRequest).Method = WebRequestMethods.Ftp.UploadFile
            Dim requestStream As Stream = req.GetRequestStream
            Dim FileStream As FileStream = File.Open(&quot;d:\rel1.xls&quot;, FileMode.Open)
            Dim buffer As Byte() = New Byte(1448) {}
            Dim bytesread As Integer
            While True
                bytesread = FileStream.Read(buffer, 0, buffer.Length)
                If bytesread = 0 Then
                    Exit While
                Else
                    requestStream.Write(buffer, 0, bytesread)
                End If
            End While
        Catch ex As Exception
            MsgBox(String.Format(&quot;EXC in button1_Click(): {0}&quot;, ex.Message))
        End Try

This code upload a file in FTP but not async.]]></description>
		<content:encoded><![CDATA[<p>Try<br />
            Dim req As WebRequest = Nothing<br />
            Dim fileURI As New Uri(txtURI.Text &amp; &#8220;/&#8221; &amp; TextBox2.Text)<br />
            req = DirectCast(FtpWebRequest.Create(fileURI), FtpWebRequest)<br />
            req.Credentials = New NetworkCredential(campousuario.Text, camposenha.Text)<br />
            DirectCast(req, FtpWebRequest).KeepAlive = False<br />
            DirectCast(req, FtpWebRequest).Method = WebRequestMethods.Ftp.UploadFile<br />
            Dim requestStream As Stream = req.GetRequestStream<br />
            Dim FileStream As FileStream = File.Open(&#8220;d:\rel1.xls&#8221;, FileMode.Open)<br />
            Dim buffer As Byte() = New Byte(1448) {}<br />
            Dim bytesread As Integer<br />
            While True<br />
                bytesread = FileStream.Read(buffer, 0, buffer.Length)<br />
                If bytesread = 0 Then<br />
                    Exit While<br />
                Else<br />
                    requestStream.Write(buffer, 0, bytesread)<br />
                End If<br />
            End While<br />
        Catch ex As Exception<br />
            MsgBox(String.Format(&#8220;EXC in button1_Click(): {0}&#8221;, ex.Message))<br />
        End Try</p>
<p>This code upload a file in FTP but not async.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-504</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Tue, 11 May 2010 15:30:21 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-504</guid>
		<description><![CDATA[And for uploadind Seans, what I need make, steps...?]]></description>
		<content:encoded><![CDATA[<p>And for uploadind Seans, what I need make, steps&#8230;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-503</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Tue, 11 May 2010 12:11:27 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-503</guid>
		<description><![CDATA[ok, thanks for your attention Seans. My error is because in this line:
Dim buffer As Byte() = New Byte(bufer) {} 
the value is always 0.
Now, I use your bufferRead in delegate and function ok.]]></description>
		<content:encoded><![CDATA[<p>ok, thanks for your attention Seans. My error is because in this line:<br />
Dim buffer As Byte() = New Byte(bufer) {}<br />
the value is always 0.<br />
Now, I use your bufferRead in delegate and function ok.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-502</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Tue, 11 May 2010 02:55:48 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-502</guid>
		<description><![CDATA[It&#039;s hard to say what&#039;s going on without seeing the rest of your code.  But maybe the first step you should take would be to do a byte-for-byte compare of the source file and the destination file, to see how the destination is different or what is missing.  My guess is that you&#039;re failing to write the final block to the destination file.]]></description>
		<content:encoded><![CDATA[<p>It&#8217;s hard to say what&#8217;s going on without seeing the rest of your code.  But maybe the first step you should take would be to do a byte-for-byte compare of the source file and the destination file, to see how the destination is different or what is missing.  My guess is that you&#8217;re failing to write the final block to the destination file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-501</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Mon, 10 May 2010 22:53:11 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-501</guid>
		<description><![CDATA[Hello.
I make this and write bytes:
  Private Sub teste(ByVal lopps As Integer, ByVal bufer As Integer, ByVal valida As Boolean)
        If Me.InvokeRequired Then
            Dim del As New testeDelegate(AddressOf teste)
            Me.Invoke(del, New Object() {lopps, bufer, valida})

        Else
            ListBox1.Items.Add(BUFFER_SIZE.ToString)

            Dim buffer As Byte() = New Byte(bufer) {}

            ListBox2.Items.Add(bufer.ToString)

            If lopps = &quot;0&quot; Then
                memstream = New FileStream(&quot;d:\testestream.doc&quot;, FileMode.Create)
                memstream.Write(buffer, 0, bufer)
            Else
                If valida = True Then
                    memstream.Close()
                Else
                    memstream.Write(buffer, 0, bufer)
                End If
            End If
        End If
    End Sub

But, I have one problem, my doc is a word document but not recognised, I receive a messenge box question me if I want convert my doc...]]></description>
		<content:encoded><![CDATA[<p>Hello.<br />
I make this and write bytes:<br />
  Private Sub teste(ByVal lopps As Integer, ByVal bufer As Integer, ByVal valida As Boolean)<br />
        If Me.InvokeRequired Then<br />
            Dim del As New testeDelegate(AddressOf teste)<br />
            Me.Invoke(del, New Object() {lopps, bufer, valida})</p>
<p>        Else<br />
            ListBox1.Items.Add(BUFFER_SIZE.ToString)</p>
<p>            Dim buffer As Byte() = New Byte(bufer) {}</p>
<p>            ListBox2.Items.Add(bufer.ToString)</p>
<p>            If lopps = &#8220;0&#8243; Then<br />
                memstream = New FileStream(&#8220;d:\testestream.doc&#8221;, FileMode.Create)<br />
                memstream.Write(buffer, 0, bufer)<br />
            Else<br />
                If valida = True Then<br />
                    memstream.Close()<br />
                Else<br />
                    memstream.Write(buffer, 0, bufer)<br />
                End If<br />
            End If<br />
        End If<br />
    End Sub</p>
<p>But, I have one problem, my doc is a word document but not recognised, I receive a messenge box question me if I want convert my doc&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bisewski</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-500</link>
		<dc:creator><![CDATA[Bisewski]]></dc:creator>
		<pubDate>Mon, 10 May 2010 11:08:59 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-500</guid>
		<description><![CDATA[Hi Sean.

Sorry my english...
I like much your code...very cool...

But I have a problem to save the doenload file. 
I dont understanding all code because I am study and I have difficult. 

Can you show mw how I can save file? Not programing...Only any step that I need...

Thanks...]]></description>
		<content:encoded><![CDATA[<p>Hi Sean.</p>
<p>Sorry my english&#8230;<br />
I like much your code&#8230;very cool&#8230;</p>
<p>But I have a problem to save the doenload file.<br />
I dont understanding all code because I am study and I have difficult. </p>
<p>Can you show mw how I can save file? Not programing&#8230;Only any step that I need&#8230;</p>
<p>Thanks&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-474</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Wed, 10 Mar 2010 15:06:32 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-474</guid>
		<description><![CDATA[Reply to danceoften,

Excellent question!  I should have been more clear in the code, or added a comment to this effect:  In the Stream.Read and Stream.BeginRead methods, the Offset parameter specifies an offset into the buffer that you&#039;re writing into (1st parameter), rather than into the stream.  You don&#039;t need to specify an offset into the stream, because when you read from a stream, the Stream object automatically advances the position into the source buffer after each Read operation.  In other words, you can just do a bunch of consecutive Stream.Read operations and you&#039;ll automatically march through the data in the stream.

Sean]]></description>
		<content:encoded><![CDATA[<p>Reply to danceoften,</p>
<p>Excellent question!  I should have been more clear in the code, or added a comment to this effect:  In the Stream.Read and Stream.BeginRead methods, the Offset parameter specifies an offset into the buffer that you&#8217;re writing into (1st parameter), rather than into the stream.  You don&#8217;t need to specify an offset into the stream, because when you read from a stream, the Stream object automatically advances the position into the source buffer after each Read operation.  In other words, you can just do a bunch of consecutive Stream.Read operations and you&#8217;ll automatically march through the data in the stream.</p>
<p>Sean</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: danceoften</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-471</link>
		<dc:creator><![CDATA[danceoften]]></dc:creator>
		<pubDate>Tue, 02 Mar 2010 13:32:25 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-471</guid>
		<description><![CDATA[excellent article:
one question is why do you always call
IAsyncResult ar = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallback), reqState);

with 0 as offset parameter ? should it be the actual offset of current reading block ?

thanx very much]]></description>
		<content:encoded><![CDATA[<p>excellent article:<br />
one question is why do you always call<br />
IAsyncResult ar = responseStream.BeginRead(reqState.bufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallback), reqState);</p>
<p>with 0 as offset parameter ? should it be the actual offset of current reading block ?</p>
<p>thanx very much</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nkg</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-433</link>
		<dc:creator><![CDATA[nkg]]></dc:creator>
		<pubDate>Mon, 16 Nov 2009 01:19:34 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-433</guid>
		<description><![CDATA[Hi Sean,

This is just what i was looking. You did mention you have not implemented following feature
&quot;Allow the user to actually store the data to a local file &quot;


Can you advise  
a.

which function i can open the file and save  the asynchronous bytes.

b. How can i cancel the download]]></description>
		<content:encoded><![CDATA[<p>Hi Sean,</p>
<p>This is just what i was looking. You did mention you have not implemented following feature<br />
&#8220;Allow the user to actually store the data to a local file &#8221;</p>
<p>Can you advise<br />
a.</p>
<p>which function i can open the file and save  the asynchronous bytes.</p>
<p>b. How can i cancel the download</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ziggy</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-426</link>
		<dc:creator><![CDATA[Ziggy]]></dc:creator>
		<pubDate>Tue, 13 Oct 2009 01:01:32 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-426</guid>
		<description><![CDATA[Nice code but the 550 error comes up on nearly half the sites I accessed. Unfortunately I think this is just lack of foresight on Microsoft&#039;s part. If you intend to use this and be relatively assured of if working on most sites then this is not the way to do it unless anyone else has a fix.]]></description>
		<content:encoded><![CDATA[<p>Nice code but the 550 error comes up on nearly half the sites I accessed. Unfortunately I think this is just lack of foresight on Microsoft&#8217;s part. If you intend to use this and be relatively assured of if working on most sites then this is not the way to do it unless anyone else has a fix.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kent_Geek</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-376</link>
		<dc:creator><![CDATA[Kent_Geek]]></dc:creator>
		<pubDate>Fri, 26 Jun 2009 15:46:35 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-376</guid>
		<description><![CDATA[Interesting code - I&#039;ve implemented very similar HTTP code, and it is working great, until I get a &quot;chunked&quot; response from a server.  In that case, in my ReadCallback method, when my bytesRead == 0, I&#039;ve only received the header, and I have no idea how to get the rest of the response.

Any ideas?  If I force the request to http 1.0, the server won&#039;t chunk the response, and things work great, but I really don&#039;t like that work-around.]]></description>
		<content:encoded><![CDATA[<p>Interesting code &#8211; I&#8217;ve implemented very similar HTTP code, and it is working great, until I get a &#8220;chunked&#8221; response from a server.  In that case, in my ReadCallback method, when my bytesRead == 0, I&#8217;ve only received the header, and I have no idea how to get the rest of the response.</p>
<p>Any ideas?  If I force the request to http 1.0, the server won&#8217;t chunk the response, and things work great, but I really don&#8217;t like that work-around.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-157</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Thu, 07 May 2009 10:27:44 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-157</guid>
		<description><![CDATA[Svit,

Maybe if you shared some more details on what about the example code doesn&#039;t work for you, I could help you.

Sean]]></description>
		<content:encoded><![CDATA[<p>Svit,</p>
<p>Maybe if you shared some more details on what about the example code doesn&#8217;t work for you, I could help you.</p>
<p>Sean</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: svit</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-155</link>
		<dc:creator><![CDATA[svit]]></dc:creator>
		<pubDate>Thu, 07 May 2009 07:16:39 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-155</guid>
		<description><![CDATA[I am developing aplication which will use asynchronous webrequests. This article is very interesting, but it seems that the link to zip file (DownloadStressTest.zip) which contains all code doesn&#039;t work. Please fix this bug.]]></description>
		<content:encoded><![CDATA[<p>I am developing aplication which will use asynchronous webrequests. This article is very interesting, but it seems that the link to zip file (DownloadStressTest.zip) which contains all code doesn&#8217;t work. Please fix this bug.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Whigham</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-143</link>
		<dc:creator><![CDATA[Scott Whigham]]></dc:creator>
		<pubDate>Wed, 18 Mar 2009 17:19:21 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-143</guid>
		<description><![CDATA[Great stuff - thanks for posting. I was googling for some sample code on async downloads and timing downloads and found this - saved me many minutes of time!]]></description>
		<content:encoded><![CDATA[<p>Great stuff &#8211; thanks for posting. I was googling for some sample code on async downloads and timing downloads and found this &#8211; saved me many minutes of time!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-117</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Thu, 05 Feb 2009 11:30:13 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-117</guid>
		<description><![CDATA[Huh, that&#039;s interesting.  So you get the error right away on the GetFileSize command?  Do you successfully get into your response callback and then see 550 when looking at the FtpWebResponse?  

Nothing jumps out at me, but I think I&#039;d try swapping out a few different things to see if you get consistent behavior, e.g.

- Do you get the same error, no matter the FTP site and file?
- Try a shorter path in FTP url and simpler filename
- Have you tried a file that just requires anonymous access, rather than using a specific user?
- If using your own FTP server, try a simpler password, e.g. w/no special characters
- Any sort of firewall or security software that would be blocking port 21?  Try turning opening up access to port 21, or turning everything temporarily off
- If you have access to the server, what do the logs on the server-side say?
- Try running as a privileged (e.g. Administrators group) user 
- Try using a network monitor or packet sniffing tool to look at the actual traffic and see if you can see the difference between your working and non-working situation
- Everything in the FtpWebRequest is really the same, i.e. the only difference between fail/no-fail is GetResponse vs. BeginGetResponse?

I&#039;d be very interested to hear what you run into..  ]]></description>
		<content:encoded><![CDATA[<p>Huh, that&#8217;s interesting.  So you get the error right away on the GetFileSize command?  Do you successfully get into your response callback and then see 550 when looking at the FtpWebResponse?  </p>
<p>Nothing jumps out at me, but I think I&#8217;d try swapping out a few different things to see if you get consistent behavior, e.g.</p>
<p>- Do you get the same error, no matter the FTP site and file?<br />
- Try a shorter path in FTP url and simpler filename<br />
- Have you tried a file that just requires anonymous access, rather than using a specific user?<br />
- If using your own FTP server, try a simpler password, e.g. w/no special characters<br />
- Any sort of firewall or security software that would be blocking port 21?  Try turning opening up access to port 21, or turning everything temporarily off<br />
- If you have access to the server, what do the logs on the server-side say?<br />
- Try running as a privileged (e.g. Administrators group) user<br />
- Try using a network monitor or packet sniffing tool to look at the actual traffic and see if you can see the difference between your working and non-working situation<br />
- Everything in the FtpWebRequest is really the same, i.e. the only difference between fail/no-fail is GetResponse vs. BeginGetResponse?</p>
<p>I&#8217;d be very interested to hear what you run into..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-116</link>
		<dc:creator><![CDATA[Carl]]></dc:creator>
		<pubDate>Thu, 05 Feb 2009 05:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-116</guid>
		<description><![CDATA[Hi Sean,

Great site and great explanation.  I&#039;ve implemented your code near verbatum, with the only changes being the default text values for the ftp server / file name and the credentials.  Without exception, as the BeginGetResponse is started, I get a 550 error (File Unavailable, no access).

I am able to download the file with synchronus code and any standard FTP client, but no matter what form of Async code I use (i.e. BeginGetResponse, yours and other examples), I always get this error.  I&#039;ve tried umpteen different combos of the file name / URI, but I get the same thing every time.

Any ideas?

Thanks, Sean!

Carl]]></description>
		<content:encoded><![CDATA[<p>Hi Sean,</p>
<p>Great site and great explanation.  I&#8217;ve implemented your code near verbatum, with the only changes being the default text values for the ftp server / file name and the credentials.  Without exception, as the BeginGetResponse is started, I get a 550 error (File Unavailable, no access).</p>
<p>I am able to download the file with synchronus code and any standard FTP client, but no matter what form of Async code I use (i.e. BeginGetResponse, yours and other examples), I always get this error.  I&#8217;ve tried umpteen different combos of the file name / URI, but I get the same thing every time.</p>
<p>Any ideas?</p>
<p>Thanks, Sean!</p>
<p>Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://stuff.seans.com/2009/01/05/using-httpwebrequest-for-asynchronous-downloads/#comment-101</link>
		<dc:creator><![CDATA[Sean]]></dc:creator>
		<pubDate>Mon, 05 Jan 2009 06:12:30 +0000</pubDate>
		<guid isPermaLink="false">http://stuff.seans.com/?p=475#comment-101</guid>
		<description><![CDATA[For reference, here are a couple of sample URIs for things to download:

HTTP:
http://mschnlnine.vo.llnwd.net/d1/pdc08/PPTX/BB01.pptx

http://www.microsoft.com/downloads/info.aspx?na=90&amp;p=&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=6ef71415-646f-4279-8b6b-193435ab2d80&amp;u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f9%2f9%2f2%2f992ba2c9-21fe-4f7c-98dc-b830c14963a6%2fIE8-WindowsVista-x86-ENU.exe

(or http://tinyurl.com/5rpcsd)

(The 2nd one is the IE8 beta for Vista).

FTP:

ftp://ftp.uci.edu/mirrors/fedora/linux/releases/10/Fedora/i386/iso/Fedora-10-i386-disc1.iso]]></description>
		<content:encoded><![CDATA[<p>For reference, here are a couple of sample URIs for things to download:</p>
<p>HTTP:<br />
<a href="http://mschnlnine.vo.llnwd.net/d1/pdc08/PPTX/BB01.pptx" rel="nofollow">http://mschnlnine.vo.llnwd.net/d1/pdc08/PPTX/BB01.pptx</a></p>
<p><a href="http://www.microsoft.com/downloads/info.aspx?na=90&#038;p=&#038;SrcDisplayLang=en&#038;SrcCategoryId=&#038;SrcFamilyId=6ef71415-646f-4279-8b6b-193435ab2d80&#038;u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f9%2f9%2f2%2f992ba2c9-21fe-4f7c-98dc-b830c14963a6%2fIE8-WindowsVista-x86-ENU.exe" rel="nofollow">http://www.microsoft.com/downloads/info.aspx?na=90&#038;p=&#038;SrcDisplayLang=en&#038;SrcCategoryId=&#038;SrcFamilyId=6ef71415-646f-4279-8b6b-193435ab2d80&#038;u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f9%2f9%2f2%2f992ba2c9-21fe-4f7c-98dc-b830c14963a6%2fIE8-WindowsVista-x86-ENU.exe</a></p>
<p>(or <a href="http://tinyurl.com/5rpcsd" rel="nofollow">http://tinyurl.com/5rpcsd</a>)</p>
<p>(The 2nd one is the IE8 beta for Vista).</p>
<p>FTP:</p>
<p><a href="ftp://ftp.uci.edu/mirrors/fedora/linux/releases/10/Fedora/i386/iso/Fedora-10-i386-disc1.iso" rel="nofollow">ftp://ftp.uci.edu/mirrors/fedora/linux/releases/10/Fedora/i386/iso/Fedora-10-i386-disc1.iso</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

