Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The remote server returned an error: (550) File unavailable(Error occured on making ftp directory)

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.

like image 575
user2493843 Avatar asked Jun 17 '13 15:06

user2493843


People also ask

What is an FTP 550 error?

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.


3 Answers

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

like image 62
Kashif Hanif Avatar answered Oct 21 '22 23:10

Kashif Hanif


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.

like image 28
ykay Avatar answered Oct 21 '22 22:10

ykay


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 */ }
like image 30
Andrew - OpenGeoCode Avatar answered Oct 21 '22 22:10

Andrew - OpenGeoCode