Freek Buurman
Freek Buurman

Reputation: 1309

Uploading multiple files with VB.Net

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

Upvotes: 1

Views: 1680

Answers (2)

feroze
feroze

Reputation: 7594

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?

Upvotes: 0

Rubens Farias
Rubens Farias

Reputation: 57956

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

IMHO, not a bad thing in your scenario.

Upvotes: 1

Related Questions