Re: Adding FTP to WebSite using C#
- From: "Bernard Cheah [MVP]" <qbernard@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 31 Oct 2007 11:17:12 +0800
Try .net dev groups.
--
Regards,
Bernard Cheah
http://www.iis.net/
http://msmvps.com/blogs/bernard/
"Mick Walker" <materialised@xxxxxxxxxxx> wrote in message
news:5om6oaFni5d2U1@xxxxxxxxxxxxxxxxxxxxx
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
http://www.mick-walker.co.uk
.
- References:
- Adding FTP to WebSite using C#
- From: Mick Walker
- Adding FTP to WebSite using C#
- Prev by Date: Re: I have some files. I want a friend of mine copy these files from my computer.
- Next by Date: Re: Cannot get FTP to Work - disconnects
- Previous by thread: Adding FTP to WebSite using C#
- Next by thread: Connect FTP virtual dir problem
- Index(es):
Relevant Pages
|
Loading