Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:13:26+00:00 2026-05-31T04:13:26+00:00

I was using Make directory to create a folders and subfolder in my ftp

  • 0

I was using Make directory to create a folders and subfolder in my ftp (using filezilla) works fine,but when i try to do in my test server (IIS FTP) doesn’t work ,throws 550,file not found or no access.so just a quick way to change the code to create subdirctory in my ftp server works fine but i know its a kinda shitty way to do like that.

Changed my code based on @Markus

        var dir = new ConsoleApplication5.Program();
        string path = "ftp://1.1.1.1/testsvr01/times/" + "testfile" + "/svr01fileName";
        string[] pathsplit = path.ToString().Split('/');
        string Firstpath = pathsplit[0] + "/" + pathsplit[1] + "/" + pathsplit[2] + "/" + pathsplit[3] + "/";
        string SecondPath = Firstpath + "/" + pathsplit[4] + "/";
        string ThirdPath = SecondPath + "/" + pathsplit[5] + "/";
        string[] paths = { Firstpath, SecondPath, ThirdPath };
        foreach (string pat in paths)
        {
           bool result= dir.EnsureDirectoryExists(pat);

            if (result==true)
            {
                //do nothing
            }
            else
            {   //create dir
                dir.createdir(pat);
            }
        }
        upload(path,filename);

    }
    private bool EnsureDirectoryExists(string pat)
    {

        try
        {
            //call the method the first path is exist ?
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(pat);
            request.Method = WebRequestMethods.Ftp.ListDirectory;
            request.Credentials = new NetworkCredential("sh", "se");
            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            {
                return true;
            }
        }
        catch (Exception ex)
        { return false; }

    }
    public void createdir(string pat)
    {
        try
        {
            FtpWebRequest createdir = (FtpWebRequest)FtpWebRequest.Create(new Uri(pat));
            createdir.Method = WebRequestMethods.Ftp.MakeDirectory;
            createdir.Credentials = new NetworkCredential("sh", "se");
            createdir.UsePassive = true;
            createdir.UseBinary = true;
            createdir.KeepAlive = false;
            FtpWebResponse response1 = (FtpWebResponse)createdir.GetResponse();
            Stream ftpStream1 = response1.GetResponseStream();
            ftpStream1.Close();
            response1.Close();
        }
        catch (Exception ex)
        {
        }

    }

Please if any of you guys find a better way,suggest me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:13:27+00:00Added an answer on May 31, 2026 at 4:13 am

    That’s a lot of code for ensuring a directory exists. Is there a Directory.Exists() method (or a similar method you could leverage)? Then you could call an EnsureDirectoryExists() before uploading.

    private bool EnsureDirectoryExists(string path)
    {
        // check if it exists
        if (Directory.Exists(path))
            return true;
    
        string parentPath = GetParentPath(path);
        if (parentPath == null)
            return false;
    
        bool result = EnsureDirectoryExists(parentPath);
    
        if (result)
        {
            CreateDirectory(path);
            return true;
        }
    
        return false;
    }
    

    Disclaimer: You might need to tweak the logic a bit and use the FTP functions, but I hope you get the point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make Friendly URLs, but when I try my PHP code works
I'm using (GNU) Make in my project. I'm currently putting one makefile per directory
I recently had an idea to create my own String class to make using
I am using this code to make the user input a name to create
I've been using make and makefiles for many many years, and although the concept
2 questions: Does using MVC make it any easier to build 508/WAI compliant sites?
I'm using GNU Make 3.81, and I have the following rule in my Makefile:
I have a C++ small project using GNU Make. I'd like to be able
I would like to know what guys are using to make diagram of your
im using jquery to make ajax requests. is it possible to detect if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.