The remote server returned an error: (550) File unavailable (error creating ftp directory)

I am developing a wpf application and I want to create a directory on ftp using C # with different usernames, and if it already exists, save the files in an existing directory.

I successfully created the validation logic of an existing directory, but when creating a new directory, I have an exception at runtime:

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

I have tested various solutions on the Internet, and most of them say that this is due to write permissions. I assign permissions to the ftp folder, but I still have a 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 have an error on FtpWebResponse .

+7
source share
3 answers

Your code looks good ....... you say that you have assigned permission too. The only problem is that you can pass the wrong "source" that causes the problem. Check your source string, it may have an error ......

the way should be like

  WebRequest request = WebRequest.Create("ftp://host.com/directory123"); 

this means that a directory will be created with the name "directory12" if you specify a path like this

  WebRequest request = WebRequest.Create("ftp://host.com/directory123/directory1234"); 

this means that " ftp://host.com/directory123/ " must exist and a new directory will be created with the name "directory1234", hope this helps

+3
source

If the problem is related to the permission problem on the Windows Server side and you have access to this FTP server, you can solve it by changing the permission and adding the β€œWrite” permission for the user name that you authenticate to the actual physical directory.

eg. If ' ftp: // host / ' points to 'c: \ inetpub \ ftproot' on your server, then enable the permission 'Write' for the user on this directory.

I set up my own IIS 7 FTP server and spent an hour or two trying to get such a simple piece of C # code to work, so I thought that I would help those who are in similar situations.

+3
source

You get this error if the directory already exists. A pretty non descriptive error message (lol). Be sure to try to catch the challenge. Request.GetResponse ()

 try { FtpWebResponse ftpResp = request.GetResponse() as FtpWebResponse; } catch ( Exception ex ) { /* ignore */ } 
+1
source

All Articles