Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp WebClient Class System.Net.WebException

Status
Not open for further replies.

tuzojazz

Programmer
Dec 26, 2005
58
MX
Hi:

I'm writing an application to downloads files from a remote server by ftp using WebClient Class

My code is something like this
---------------------------------------------------------
Try
Dim remoteFile As String = "ftp://187.153.7.42/songs/TRACK_NO01.MP3"
Dim client As New WebClient
client.Credentials = New NetworkCredential("user1", "password")
client.DownloadFile(remoteFile, "Z:\TRACK_NO01.MP3")
MsgBox("file downloaded!")

Catch ex As Exception
MsgBox(ex.ToString)
End Try
------------------------------------------------------
When I download small files (600 KB) it works but when I download bigger files(3 MB) I get this Exception after few minutes

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.


I suposse this is because timeout

Is there a property or method to increase timeout in WebClient Class?

or

do I need to set something on windows?

My windows is server 2003 enterprise edition

Thanks!
 
tuzojazz,

This is actually a bug in .Net where the underlying connection is closed before the request is complete. You can add something like this to your class where the connection is being handled
Code:
Protected Overloads Overrides Function GetWebRequest(ByVal uri As Uri) As WebRequest
    Dim webRequest As HttpWebRequest = DirectCast(MyBase.GetWebRequest(uri), HttpWebRequest)

    webRequest.KeepAlive = True

    Return webRequest
End Function

Application Developer: VB.Net, Qik III, SQL 2000/2005

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Let's fact it, most computer users have the brain of a Spider Monkey"
~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top