Q:

Create folder on ftp

I am using method to create folder on ftp i want get exception if folder already exsists how to make it over write the existing folder
using System; using System.Net;

class Test {
    static void Main()
    {
        WebRequest request = WebRequest.Create("ftp://host.com/directory");
        request.Method = WebRequestMethods.Ftp.MakeDirectory;
        request.Credentials = new NetworkCredential("user", "pass");
        using (var resp = (FtpWebResponse) request.GetResponse())
        {
            Console.WriteLine(resp.StatusCode);
        }
    } }

it is "remote server returned error (550) file not found"

A:

Well, "I want to get exception if folder already exists" and "how to make it overwrite the existing folder" are two opposing questions.
At any rate, I just implemented code to do this the other day. Just check if the directory already exists first. And then respond based on that. There's no point in trying to create a directory that already exists.
And if you need to overwrite it somehow, then delete the existing directory before creating the new one.
You can see the code I wrote for this in the article An FtpClient Class and WinForm Control, although it will just overwrite existing content.

