This is an function that downloads a single file from an FTP server and saves it to disk This is my first time doing anything with FTP, please let me know if i have missed anything.

public void DownloadFile(string fileloc, string saveLoc)
{
try
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(fileloc);

using (var response = (FtpWebResponse)request.GetResponse())
{
using (var fileStream = File.Create(saveLoc))
{
response.GetResponseStream().CopyTo(fileStream);
}
}
}
catch (Exception EX)
{
throw EX;
}
}


First, like ANeves said, the only thing your catch does is that it resets the exception's stack trace, which is not what you want to do. Just remove the try/catch completely, it serves no purpose here.

Second, I don't see any reason to use WebRequest here, using WebClient is much simpler.

Also, you might want to have better parameter names: fileloc doesn't say what exactly it is, and doesn't use the usual capitalization. And loc is unnecessarily abbreviated (you're not trying to write a Twitter post where every character counts, readability is more important) and too ambiguous.

public void DownloadFile(string url, string savePath)
{
var client = new WebClient();
}


This method could be rewritten as one expression, but I probably wouldn't do that:

public void DownloadFile(string url, string savePath)
{
}

• Almost everything I have to say. – Philippe Lavoie Jun 18 '12 at 23:31

When you rethrow an exception using throw ex; you refresh its stacktrace. (Frame?) This means the exception will seem to have been initially raised at your throw ex; line, and loses its previous stacktrace.

You want to simply throw; - like this:

try {
new Profiterole(); // BOOM!
} catch (Exception ex) {
throw; // Preserves the stacktrace, showing that the Exception was raised in InitGlacing();
}


As suggested by @svick: better yet, don't have a try/catch at all; it serves no purpose here.

• Better yet, don't have a try/catch at all. It serves mo purpose here. – svick Jun 18 '12 at 15:55

It is always good to have a buffer parameter or at least overload the function to provide one. I think this justifies using the FtpWebRequest vs the WebClient as increasing your buffer can greatly increase your transfer speed and saturate all available network bandwidth. You will not see any improvement on small files but if you are downloading anything over 100mb is when you will start seeing a noticiceable difference.

responseStream.CopyTo(fileStream, buffer)