2

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()?

Community
  • 1
  • 1
PiousVenom
  • 6,888
  • 11
  • 47
  • 86
  • perhaps your login does not have the required permissions – Sam Axe Jan 30 '13 at 20:37
  • @Dan-o: I thought about that, looked into it, but the permissions are there. – PiousVenom Jan 30 '13 at 20:47
  • Are you sure that the path leading to the file is accessible and existing? There was a similar discussion and solution in StackOverflow: http://stackoverflow.com/questions/9118286/ftp-makedirectory-nested-structure – Axel Kemper Jan 30 '13 at 22:13
  • Yes, I've verified the path to my server. I'm essentially trying to create a Folder in my base directory(`ftp://my-site.com`), so my directory looks like `ftp://my-site.com/newFolder`. – PiousVenom Jan 31 '13 at 03:16

1 Answers1

1

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.

PiousVenom
  • 6,888
  • 11
  • 47
  • 86