views:

350

answers:

2

I need to upload multiple files in a winforms application. So far I've been using a webclient and while this is working fine I'm wondering if there is a better way for doing this. Does the webclient make a new connection for every request or does the connection persists between uploads?

Dim Ftpclient As New System.Net.WebClient()
Ftpclient.Credentials = New System.Net.NetworkCredential(username, password)

Dim Files As New Dictionary(Of String, String)

''//Fill dictionary with items for upload here

For Each RemoteFile As String In Files.Keys
    Ftpclient.UploadFile(RemoteFile, Files(RemoteFile))
Next
+1  A: 

It'll create a new TCP connection for every file, because it's way HTTP works.

IMHO, not a bad thing in your scenario.

Rubens Farias
It's not quite the way FTP works. Still, System.Net doesn't offer an alternative to keeping the command port connection opened.
Hans Passant
sure, but note OP create a `System.Net.WebClient` instance, not `System.Net.FtpWebRequest`
Rubens Farias
A: 

It depends on what protocl you are using for upload. If you are using HTTP, then the client will reuse the previous connection if it can. I am not sure about FTP - I think FTP also supports keep-alive.

In any case, if you are concerned about performance, you should use Wireshark to see how the connection usage is being accomplished. Is it creating a new connection everytime?

feroze