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
.
A 550 response code may be sent in response to any command requiring the server to access a local file. It is a permanent negative response, which means the client is discouraged from sending the command again since the server will respond with the same response code.
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
WebRequest request = WebRequest.Create("ftp://host.com/directory123");
it mean directory will be created with name "directory12" if your are specifying path like this
WebRequest request = WebRequest.Create("ftp://host.com/directory123/directory1234");
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.
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()
try
{
FtpWebResponse ftpResp = request.GetResponse() as FtpWebResponse;
}
catch ( Exception ex ) { /* ignore */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With