all groups > iis ftp > october 2007 >
You're in the

iis ftp

group:

Adding FTP to WebSite using C#



Adding FTP to WebSite using C# Mick Walker
10/29/2007 1:50:03 PM
iis ftp: Hi All,

I am attempting to add ftp support to a website I create. To create the
website, I use the following function:

public class WebSites {
public const string FTPSERVICE = "/MSFTPSVC";
public const string IIS = "IIS://";
public const string WEBSERVICE = "/W3SVC";

public static bool AddSite(WebSites NewWebSite) {
string strIISPath = IIS + NewWebSite.ServerName + WEBSERVICE;

string strPhysicalPath = "\\\\" + NewWebSite.ServerName +
"\\hosts\\" + NewWebSite.SiteName + "\\httpdocs";
// Try to create the Directory
Directory.CreateDirectory("\\\\" + NewWebSite.ServerName +
"\\hosts\\" + NewWebSite.SiteName);


// Create Restricted Directories
Directory.CreateDirectory("\\\\" + NewWebSite.ServerName +
"\\hosts\\" + NewWebSite.SiteName +
"\\httpdocs");
Directory.CreateDirectory("\\\\" + NewWebSite.ServerName +
"\\hosts\\" + NewWebSite.SiteName +
"\\httpdocs\\App_Code");

Directory.CreateDirectory("\\\\" + NewWebSite.ServerName +
"\\hosts\\" + NewWebSite.SiteName +
"\\httpdocs\\App_Data");
Directory.CreateDirectory("\\\\" + NewWebSite.ServerName +
"\\hosts\\" + NewWebSite.SiteName +
"\\httpdocs\\bin");
Directory.CreateDirectory("\\\\" + NewWebSite.ServerName +
"\\hosts\\" + NewWebSite.SiteName +
"\\private");

// Set the Websites Physical Path
NewWebSite.PhysicalPath = "\\\\" + NewWebSite.ServerName +
"\\hosts\\" + NewWebSite.SiteName +
"\\httpdocs";
// Create the New Website
ServerManager iisManager =
ServerManager.OpenRemote(NewWebSite.ServerName);
iisManager.Sites.Add(NewWebSite.SiteName, "http",
NewWebSite.HostHeader, strPhysicalPath);
iisManager.Sites.Add(NewWebSite.SiteName, "ftp",
NewWebSite.HostHeader, strPhysicalPath);
iisManager.CommitChanges();



// Use Active Directory to set the website permissions
DirectoryEntry objIISDirectoryEntry = new
DirectoryEntry(strIISPath + "/" + GetSiteID(strIISPath,
NewWebSite.SiteName));
// Assign property to Website
objIISDirectoryEntry.Properties["EnableDirBrowsing"][0] =
NewWebSite.HasBrowseAccess;
objIISDirectoryEntry.Properties["AccessExecute"][0] =
NewWebSite.HasExecuteAccess;
objIISDirectoryEntry.Properties["AccessRead"][0] =
NewWebSite.HasReadAccess;
objIISDirectoryEntry.Properties["AccessWrite"][0] =
NewWebSite.HasWriteAccess;
objIISDirectoryEntry.Properties["AuthAnonymous"][0] =
NewWebSite.IsAnonymousAccessAllow;
objIISDirectoryEntry.Properties["AuthBasic"][0] =
NewWebSite.IsBasicAuthenticationSet;
objIISDirectoryEntry.Properties["AuthNTLM"][0] =
NewWebSite.IsNTLMAuthenticationSet;

// Save Changes
objIISDirectoryEntry.CommitChanges();

// Close both directory object.
objIISDirectoryEntry.Close();
return true;
}

It uses a Mixture of Active Directory and System.Web.Administration
classes to automate the process.
How can I also create a default website with the same document root as
the site I have just created?
Kind regards
Mick Walker
--
Mick Walker
Software Engineer

Re: Adding FTP to WebSite using C# Bernard Cheah [MVP]
10/31/2007 12:00:00 AM
Try .net dev groups.

--
Regards,
Bernard Cheah
http://www.iis.net/
http://msmvps.com/blogs/bernard/


[quoted text, click to view]

AddThis Social Bookmark Button