• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 629
  • Last Modified:

how to create directory in Ftp path

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
BDPL
Asked:
BDPL
2 Solutions
 
ashraf882Commented:
0
 
Sathish DVSoftware EngineerCommented:
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
Independent Software Vendors: 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!

 
abelallenCommented:
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
 
BDPLAuthor Commented:
Based on these methods, i got my solution with littile bit of changes.
Thank you.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now