?
Solved

how to create directory in Ftp path

Posted on 2010-01-12
6
Medium Priority
?
596 Views
Last Modified: 2013-12-17
Hi,
I have a ftp path like: "ftp://123456789/DataStore2/CC/FAQ" , this is existing path.

I want to add more folders, means create directories in that existing path.

(previously i was tried to create directories in my system path by using System.IO.Directory.CreateDirectory()).
But in Remote Path.....i got failed.

please help me
thanx.
0
Comment
Question by:BDPL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 11

Expert Comment

by:ashraf882
ID: 26291658
0
 
LVL 12

Expert Comment

by:Nirmalan Nagenthiran
ID: 26291858
0
 
LVL 4

Assisted Solution

by:Sathish DV
Sathish DV earned 300 total points
ID: 26292267
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.AccessControl;

namespace CreateRemoteDirectory
{
    class Program
    {
        static void Main(string[] args)
        {

            string path = @"\\192.168.1.2\Test\Test12";
            //I assume that: Your file server ip is 192.168.1.2
            //you have shared the "Test" folder and set Full control, then you want to create "Test12" folder and add domain account for "Test12" ACL  
            if (Directory.Exists(path))                    
            {            
                return;        
            }        
            DirectoryInfo dirInfo = Directory.CreateDirectory(path);            
            DirectoryInfo dInfo = new DirectoryInfo(path);        
            // Get a DirectorySecurity object that represents the        
            // current security settings.        
            DirectorySecurity dSecurity = dInfo.GetAccessControl();        
            string domainName = "DomainName";        
            string identity = "UserName";        
            // Add the FileSystemAccessRule to the security settings.                
            FileSystemAccessRule fsr = new FileSystemAccessRule(domainName + @"\" + identity,
                System.Security.AccessControl.FileSystemRights.ReadData|
                System.Security.AccessControl.FileSystemRights.WriteData|
                System.Security.AccessControl.FileSystemRights.Modify,
                AccessControlType.Allow);
            dSecurity.AddAccessRule(fsr);
            // Set the new access settings.        
            dInfo.SetAccessControl(dSecurity);
           
        }
    }
}


try this.
0
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 
LVL 2

Accepted Solution

by:
abelallen earned 450 total points
ID: 26301909
Hi BDPL,

Try something like this..

CreateDirectory("ftp://192.168.0.55/",string.Format("/ftproot/{0}/{1}/", "aaa", "2"), "sa","sa");

static bool CreateDirectory(string ftpUri, string path, string login, string password)
    {
        string[] dir = path.Split('/');
        string tempUri = "";// ftpUri.Trim('/') + "/";
        foreach (string d in dir)
        {
            if(d.IsNullOrEmpty())
                continue;

            bool? isExists = IsExistsDirectory(ftpUri+tempUri, d, login, password);
            tempUri += (d + "/");

            if(isExists==false)
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUri + "%2f" + tempUri.Trim('/'));
                request.KeepAlive = true;
                request.Method = WebRequestMethods.Ftp.MakeDirectory;
                request.Proxy = null;
                request.Credentials = new NetworkCredential(login, password);
                request.UseBinary = true;
                request.UsePassive = false;
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            }
            if (isExists == null)
                return false;

            if (isExists.Value)
                continue;
        }
        return true;
    }

Refards,
Abel Allen
0
 

Author Closing Comment

by:BDPL
ID: 31676000
Based on these methods, i got my solution with littile bit of changes.
Thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question