Advertisement
Advertisement
| 12.06.2007 at 03:19PM PST, ID: 23007539 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: |
Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
fdb.SelectedPath = Application.StartupPath
fdb.ShowDialog()
Dim tempSaveDir = fdb.SelectedPath
Try
Dim outputStream As FileStream = New FileStream(fdb.SelectedPath + "\\" + lbFiles.SelectedItem, FileMode.OpenOrCreate)
Dim clsRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(tempurl & "/" & lbFiles.SelectedItem), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential(Form1.tbUser.Text, Form1.tbPass.Text)
clsRequest.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
Dim response As FtpWebResponse = clsRequest.GetResponse
Dim ftpStream As Stream = response.GetResponseStream()
Dim cl As String = response.ContentLength
MsgBox(cl)
Dim bufferSize As Integer = 1024
Dim readCount As Integer
Dim buffer(bufferSize) As Byte
Dim tempCount = 0
ProgressBar.Value = 0
While True
readCount = ftpStream.Read(buffer, 0, bufferSize)
If readCount > 0 Then
outputStream.Write(buffer, 0, readCount)
'ProgressBar.Value = (tempCount / cl) * 100
End If
'MsgBox(outputstre)
End While
ftpStream.Flush()
outputStream.Flush()
ftpStream.Dispose()
outputStream.Dispose()
response.Close()
Catch ui As UriFormatException
MsgBox("ui " + ui.Message)
Catch io As IOException
MsgBox("IO " + io.Message)
Catch ex As Exception
MsgBox("EX " + ex.Message)
End Try
End Sub
ERROR I receive when trying to download I get about 75% of the way thru the download -
EX Cannot access adisposed object.
Object name: 'system.net.sockets.networkstream'.
Then it just stops and aborts the download all this doesnt make sense because im not disposing any object untill after the read AND I commented the code out and still doenst work.
|