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