I am developing a wpf application and I want to make a directory on ftp using C# with different usernames and if it already exists then save files on existing directory.
I've successfully created the logic of checking the existing directory but while creating a new directory I've got an exception on runtime:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
I've checked different solutions on the internet and most are saying that it is due to write permissions. I am assigning the ftp folder write permissions, but I am still having the problem. Please Help?
Here is my code:
static void CreateFtpFolder(string source)
{
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(source);
request.Credentials = new NetworkCredential(ftpusername, ftppassword);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.UsePassive = true;
request.UseBinary = false;
request.KeepAlive = false;
request.Proxy = null;
FtpWebResponse ftpResp = request.GetResponse() as FtpWebResponse;
}
I am having the error on FtpWebResponse
.
You get that error if the directory already exists. Pretty non-descriptive error message (lol). Must put a try catch around the call to request.GetResponse()
Your code look fine.......you are saying that you have assigned permission too. The only problem is that you may be passing a wrong "Source"which is causing problem..Check your source string it may have an error......
path should be like
it mean directory will be created with name "directory12" if your are specifying path like this
this mean "ftp://host.com/directory123/" should already exist and new directory will be created with name "directory1234" hope it will help
If the problem is a Windows Server-side permission issue and you have access to this FTP server, you may be able to resolve it by modifying the permission and adding 'Write' permission for the username that you are authenticating with on the actual physical directory.
e.g. If 'ftp://host/' points to 'c:\inetpub\ftproot' on your server, then allow 'Write' permission for the user on that directory.
I was setting up my own IIS 7 FTP server and spent a good hour or two trying to get such a simple snippet of C# client code to work, so thought I'd contribute for those in similar situations.