Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am writing a piece of code to make directory on ftp using c# and everything seems fine but i've got an exception on runtime that "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)." and i am stuck i don't know what to do. Please look into it and help me?

The code i am using goes here:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace makedirectory
{
    class Program
    {
        static void Main(string[] args)
        {
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://127.0.0.1/" + "NewDirectory");
  request.Credentials = new NetworkCredential("anonymous", "anonymous");
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;
            Console.WriteLine("Getting the response");

            request.Method = WebRequestMethods.Ftp.MakeDirectory;
            
            using (var resp = (FtpWebResponse)request.GetResponse())
            {
                Console.WriteLine(resp.StatusCode);
            }

        }
        
    }
}
Posted
Updated 21-Jun-16 19:44pm
v2
Comments
manognya kota 14-Jan-12 3:48am    
check whether the FTP folder is having permission for anonymous system read/write.
manognya kota 14-Jan-12 3:48am    
In the server Go to Control Panel>Internet information Services, expand FTP Sites, right click in Default FTP Site and go to Properties, in the tab Particular directory check Write and press OK.
AAMERSAEED 13-Feb-12 16:34pm    
Thank you:)......i've done it.

C#
using System;
using System.Net;

class Test
{
    static void Main()
    {
        WebRequest request = WebRequest.Create("ftp://host.com/directory");
        request.Method = WebRequestMethods.Ftp.MakeDirectory;
        request.Credentials = new NetworkCredential("user", "pass");
        using (var resp = (FtpWebResponse) request.GetResponse())
        {
            Console.WriteLine(resp.StatusCode);
        }
    }
}
 
Share this answer
 
probably you do not have write permission to the directory you are trying to access and create a new directory inside that.
 
Share this answer
 
Comments
Aneesh swaroop 7-Dec-17 3:30am    
I can write file but cannot able to write any directory what to do?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900