views:

94

answers:

1

Hi There, Could anyone guide me as to the best way to upload a collection of files from a directory to a server from within a WPF client. We have ftp access, and as such I have been looking at WebClient.UploadFile.

There seems to be a number of methods available through webclient though, and Im not sure which would be the most suitable.

Thanks in advance,

A: 

Just use WebClient.UploadFile or WebClient.UploadFileAsync to upload the files, with one call per file.

This can be as simple as:

WebClient wc = new WebClient();

foreach(var filePath in files)
    wc.UploadFile("ftp://myserver.com/path", filePath);
Reed Copsey
Thanks - by the way, it appears that there is no way to authenticate on the ftp server prior to upload. Is this the case?
Sergio
Yes, you can. Just set the WebClient.Credentials property prior to calling UploadFile: http://msdn.microsoft.com/en-us/library/system.net.webclient.credentials.aspx
Reed Copsey