PiousVenom
PiousVenom

Reputation: 6918

Creating a directory on FTP server

I'm trying to create a directory on my FTP server. Google search shows me this question here. So I followed what Jon wrote as his answer, and have:

    private static void MakeDirectory(string directory)
    {
        Log("Making directory...");

        var request = (FtpWebRequest)WebRequest.Create(directory);

        request.Method = WebRequestMethods.Ftp.MakeDirectory;
        request.Credentials = new NetworkCredential("user", "pass");

        try
        {
            using (var resp = (FtpWebResponse)request.GetResponse()) // Exception occurs here
            {
                Log(resp.StatusCode.ToString());
            }
        }
        catch (WebException ex)
        {
            Log(ex.Message);
        }
    }

I have a method to verify that the directory exists:

    public bool DirectoryExists(string directory)
    {
        bool directoryExists;

        var request = (FtpWebRequest)WebRequest.Create(directory);
        request.Method = WebRequestMethods.Ftp.ListDirectory;
        request.Credentials = new NetworkCredential("user", "pass");

        try
        {
            using (request.GetResponse())
            {
                directoryExists = true;
            }
        }
        catch (WebException)
        {
            directoryExists = false;
        }
        return directoryExists;
    }

The check actually works. If it exists, it returns true, if not, it returns false. However, whenever I go to run my MakeDirectory(), I get an exception on the line stated above:

The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

Am I missing something? Why would the GetResponse() work for my directory check, but not for my MakeDirectory()?

Upvotes: 2

Views: 3318

Answers (1)

PiousVenom
PiousVenom

Reputation: 6918

As it turns out, this was an issue on the part of the company who runs our web servers. They did some FTP update last night that affected not only myself, but all their clients. They have since fixed the problem. It just took them a day to admit that it was their fault.

Upvotes: 1

Related Questions