示例#1
0
        public static PropertyBag SerializeSite(Site site)
        {
            PropertyBag bag = new PropertyBag();

            bag[FtpSiteGlobals.Site_Name] = site.Name;
            bag[FtpSiteGlobals.Site_ID]   = site.Id;
            Application application = site.Applications["/"];

            bag[FtpSiteGlobals.VirtualDirectory_PhysicalPath] = string.Empty;
            if (application != null)
            {
                VirtualDirectory directory = application.VirtualDirectories["/"];
                if (directory != null)
                {
                    bag[FtpSiteGlobals.VirtualDirectory_PhysicalPath] = directory.PhysicalPath;
                    bag[FtpSiteGlobals.VirtualDirectory_UserName]     = directory.UserName;
                    bag[FtpSiteGlobals.VirtualDirectory_Password]     = directory.Password;
                }
            }
            bag[FtpSiteGlobals.Site_Bindings] = GetFtpBindings(site.Bindings);
            FtpSite ftpSiteElement = FtpHelper.GetFtpSiteElement(site);

            bag[FtpSiteGlobals.FtpSite_Status] = (int)ftpSiteElement.State;
            return(bag);
        }
示例#2
0
        public static FtpSite GetFtpSite(ManagementConfigurationPath configPath, ServerManager serverManager)
        {
            FtpSite ftpSiteDefaultElement = null;

            if (configPath.PathType == ConfigurationPathType.Server)
            {
                ftpSiteDefaultElement = GetFtpSiteDefaultElement(serverManager.SiteDefaults);
            }
            else
            {
                Site site = serverManager.Sites[configPath.SiteName];
                if (site == null)
                {
                    WebManagementServiceException exception = new WebManagementServiceException("GetSettingsExceptionError", string.Empty);
                    throw exception;
                }
                if (!IsFtpSite(site))
                {
                    WebManagementServiceException exception2 = new WebManagementServiceException("SiteIsNotFtpSiteExceptionError", string.Empty);
                    throw exception2;
                }
                ftpSiteDefaultElement = GetFtpSiteElement(site);
            }
            if (ftpSiteDefaultElement == null)
            {
                WebManagementServiceException exception3 = new WebManagementServiceException("GetSettingsExceptionError", string.Empty);
                throw exception3;
            }
            return(ftpSiteDefaultElement);
        }
        public void AddSite(PropertyBag bag)
        {
            // ensure bag not empty
            if (bag == null)
            {
                throw new ArgumentNullException("bag");
            }

            // ensure site not exists
            string name = (string)bag[FtpSiteGlobals.Site_Name];

            if (ServerManager.Sites[name] != null)
            {
                throw new Exception("SiteAlreadyExistsExceptionError");
            }

            // ensure site path
            string directory = (string)bag[FtpSiteGlobals.VirtualDirectory_PhysicalPath];

            if (!Directory.Exists(FileUtils.EvaluateSystemVariables(directory)))
            {
                throw new Exception("SiteDirectoryDoesNotExistExceptionError");
            }

            // ensure site binding
            PropertyBag bag2 = (PropertyBag)bag[FtpSiteGlobals.Site_SingleBinding];

            if (bag2 == null)
            {
                throw new ArgumentNullException("bindingBag");
            }

            string bindingInformation = (string)bag2[FtpSiteGlobals.BindingInformation];

            SitesHelper.DeserializeSiteProperties(ServerManager.Sites.Add(name, "ftp", bindingInformation, directory), bag);
            // authorization
            PropertyBag authBag = (PropertyBag)bag[FtpSiteGlobals.Authorization_Rule];

            if (authBag != null)
            {
                AddAuthorizationRules(name, authBag);
            }

            ServerManager.CommitChanges();
            Site site = ServerManager.Sites[name];

            try
            {
                FtpSite ftpSiteElement = FtpHelper.GetFtpSiteElement(site);
                //
                if (ftpSiteElement.ServerAutoStart)
                {
                    ftpSiteElement.Start();
                }
            }
            catch
            {
            }
        }
示例#4
0
        public static PropertyBag SerializeSiteDefaults(ServerManager serverManager)
        {
            FtpSite     ftpSiteDefaultElement = FtpHelper.GetFtpSiteDefaultElement(serverManager.SiteDefaults);
            PropertyBag bag = new PropertyBag(true);

            SerializeFtpSiteProperties(ftpSiteDefaultElement, bag);
            return(bag);
        }
示例#5
0
 /// <summary>
 /// 创建新的FtpSite对象
 /// </summary>
 public void CreateFtpSite()
 {
     _FtpSite = new FtpSite(HostName, Port, UserName, Password);
     _FtpSite.IsShowHidenFile       = IsShowHidenFile;
     _FtpSite.IsUseMlsdToListFolder = IsUseMlsdToListFolder;
     _FtpSite.IsNotSupportFEAT      = IsNotSupportFEAT;
     _FtpSite.StringEncoding        = StringEncoding;
     _FtpSite.BufferSize            = BufferSize;
 }
        /// <summary>
        /// Gets state of the site with sepcified name.
        /// </summary>
        /// <param name="siteName">Site's name to get state for.</param>
        /// <returns>Site's state.</returns>
        public ServerState GetSiteState(string siteName)
        {
            FtpSite ftpSite = GetIisFtpSite(siteName);

            if (ftpSite == null)
            {
                return(ServerState.Unknown);
            }
            return(ConvertSiteStateToServerState(ftpSite.State));
        }
        /// <summary>
        /// Gets ftp site with given name.
        /// </summary>
        /// <param name="siteName">Site's name.</param>
        /// <returns>Ftp site.</returns>
        public FtpSite GetIisFtpSite(string siteName)
        {
            Site site = this.GetIisSite(siteName);

            if (site == null)
            {
                throw new ArgumentException("Site with given name doesn't exist.", "siteName");
            }
            FtpSite ftpSiteElement = FtpHelper.GetFtpSiteElement(site);

            ftpSiteElement.SiteServiceId = Convert.ToString(site.Id);
            //
            return(ftpSiteElement);
        }
示例#8
0
 public void UpdateSite(FtpSite site)
 {
     try
     {
         Log.WriteStart("'{0}' UpdateSite", ProviderSettings.ProviderName);
         FtpProvider.UpdateSite(site);
         Log.WriteEnd("'{0}' UpdateSite", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' UpdateSite", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
示例#9
0
 public FtpSite GetSite(string siteId)
 {
     try
     {
         Log.WriteStart("'{0}' GetSite", ProviderSettings.ProviderName);
         FtpSite result = FtpProvider.GetSite(siteId);
         Log.WriteEnd("'{0}' GetSite", ProviderSettings.ProviderName);
         return(result);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' GetSite", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
示例#10
0
 public string CreateSite(FtpSite site)
 {
     try
     {
         Log.WriteStart("'{0}' CreateSite", ProviderSettings.ProviderName);
         string result = FtpProvider.CreateSite(site);
         Log.WriteEnd("'{0}' CreateSite", ProviderSettings.ProviderName);
         return(result);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' CreateSite", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
示例#11
0
 public static void SerializeFtpSiteProperties(FtpSite ftpSite, PropertyBag bag)
 {
     bag[FtpSiteGlobals.FtpSite_AutoStart] = ftpSite.ServerAutoStart;
     bag[FtpSiteGlobals.Connections_UnauthenticatedTimeout] = ftpSite.Connections.UnauthenticatedTimeout;
     bag[FtpSiteGlobals.Connections_ControlChannelTimeout]  = ftpSite.Connections.ControlChannelTimeout;
     bag[FtpSiteGlobals.Connections_DisableSocketPooling]   = ftpSite.Connections.DisableSocketPooling;
     bag[FtpSiteGlobals.Connections_ServerListenBacklog]    = ftpSite.Connections.ServerListenBacklog;
     bag[FtpSiteGlobals.Connections_DataChannelTimeout]     = ftpSite.Connections.DataChannelTimeout;
     bag[FtpSiteGlobals.Connections_MinBytesPerSecond]      = ftpSite.Connections.MinBytesPerSecond;
     bag[FtpSiteGlobals.Connections_MaxConnections]         = ftpSite.Connections.MaxConnections;
     bag[FtpSiteGlobals.Connections_ResetOnMaxConnection]   = ftpSite.Connections.ResetOnMaxConnections;
     bag[FtpSiteGlobals.Ssl_ServerCertHash]       = ftpSite.Security.Ssl.ServerCertHash;
     bag[FtpSiteGlobals.Ssl_ControlChannelPolicy] = (int)ftpSite.Security.Ssl.ControlChannelPolicy;
     bag[FtpSiteGlobals.Ssl_DataChannelPolicy]    = (int)ftpSite.Security.Ssl.DataChannelPolicy;
     bag[FtpSiteGlobals.Ssl_Ssl128] = ftpSite.Security.Ssl.Ssl128;
     bag[FtpSiteGlobals.Authentication_AnonymousEnabled] = ftpSite.Security.Authentication.AnonymousAuthentication.Enabled;
     bag[FtpSiteGlobals.Authentication_BasicEnabled]     = ftpSite.Security.Authentication.BasicAuthentication.Enabled;
 }
        public PropertyBag EditSiteProperties(PropertyBag bag)
        {
            if (bag == null)
            {
                throw new ArgumentNullException("bag");
            }
            string      siteName   = (string)bag[100];
            PropertyBag bindingBag = (PropertyBag)bag[0x68];

            if (bindingBag != null)
            {
                this.AddSiteBinding(siteName, bindingBag);
            }
            Site site = ServerManager.Sites[siteName];

            if (site == null)
            {
                throw new Exception("SiteDoesNotExistCannotEditExceptionError");
            }

            SitesHelper.DeserializeSiteProperties(site, bag);
            PropertyBag authBag = (PropertyBag)bag[0x1a6];

            if (authBag != null)
            {
                this.AddAuthorizationRules(siteName, authBag);
            }
            //
            ServerManager.CommitChanges();
            //
            site = ServerManager.Sites[siteName];
            try
            {
                FtpSite ftpSiteElement = FtpHelper.GetFtpSiteElement(site);
                if (ftpSiteElement.ServerAutoStart)
                {
                    ftpSiteElement.Start();
                }
            }
            catch
            {
            }
            return(SitesHelper.SerializeSite(site));
        }
示例#13
0
 /// <summary>
 /// 清除FtpSite对象
 /// </summary>
 public void ClearFtpSite()
 {
     _FtpSite = null;
 }
示例#14
0
        private void StartFtpUploadInThread()
        {
            try
            {
                Thread.Sleep(50);

                String host     = ftpDestNode.Site.host;
                String username = ftpDestNode.Site.username;
                String pwd      = ftpDestNode.Site.pwd;



                String targetfolder = ftpDestNode.Path;

                if (sourceFiles != null)
                {
                    int count      = sourceFiles.Count();
                    int iFileCount = 0;


                    foreach (var file in sourceFiles)
                    {
                        string basicProgress = (++iFileCount).ToString() + " of " + count.ToString() + " : " + file.Name;

                        progress.SetProgress(basicProgress);
                        if (this.cancelled)
                        {
                            break;
                        }

                        FtpWebResponse response    = null;
                        FileStream     inputStream = null;
                        Stream         ftpStream   = null;

                        while (!this.cancelled)
                        {
                            bool      success       = false;
                            Exception lastException = null;

                            for (int i = 0; i < 4 && !this.cancelled; i++)
                            {
                                try
                                {
                                    progress.SetProgress(basicProgress + " - Connecting");

                                    lock (FtpSite.LockInstance())
                                    {
                                        string        ftpfullpath = "ftp://" + host + targetfolder + "/" + file.Name;
                                        FtpWebRequest ftp         = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);

                                        ftp.UseBinary = true;
                                        ftp.KeepAlive = true;
                                        ftp.Method    = WebRequestMethods.Ftp.UploadFile;
                                        ftp.Timeout   = 2000;

                                        ftp.Credentials = new NetworkCredential(username, pwd);

                                        response = (FtpWebResponse)ftp.GetResponse();


                                        inputStream = File.OpenRead(file.FullName);


                                        //  ftpStream = response.GetResponseStream();
                                        ftpStream = ftp.GetRequestStream();


                                        progress.SetProgress(basicProgress + " - Reponse Recieved");


                                        int    bufferSize = 2048 * 2 * 2 * 2 * 2 * 2 * 2;
                                        int    readCount;
                                        int    totalCount = 0;
                                        byte[] buffer     = new byte[bufferSize];

                                        readCount = inputStream.Read(buffer, 0, bufferSize);
                                        while (readCount > 0 & !this.cancelled)
                                        {
                                            totalCount += readCount;
                                            progress.SetProgress(basicProgress + " - Uploading: " + totalCount.ToString()
                                                                 );

                                            ftpStream.Write(buffer, 0, readCount);
                                            readCount = inputStream.Read(buffer, 0, bufferSize);
                                        }
                                        success = true;
                                        progress.SetProgress(basicProgress + " - Completed");
                                    }
                                    break;
                                }
                                catch (Exception e)
                                {
                                    lastException = e;
                                }
                                finally
                                {
                                    try { if (ftpStream != null)
                                          {
                                              ftpStream.Close();
                                          }
                                    }
                                    catch (Exception) { }

                                    try { if (inputStream != null)
                                          {
                                              inputStream.Close();
                                          }
                                    }
                                    catch (Exception) { }

                                    try { if (response != null)
                                          {
                                              response.Close();
                                          }
                                    }
                                    catch (Exception) { }
                                }
                            }
                            if (this.cancelled)
                            {
                                return;
                            }

                            if (!success)
                            {
                                DialogResult keepGoing = MessageBox.Show("Keep Trying? Failed after 4 attempts to download: "
                                                                         + file + " Exception: " + lastException.Message
                                                                         , "FTP Failure"
                                                                         , MessageBoxButtons.OKCancel
                                                                         , MessageBoxIcon.Error
                                                                         , MessageBoxDefaultButton.Button1);

                                if (keepGoing != DialogResult.OK)
                                {
                                    return; // Don't true any more.
                                }
                            }

                            if (success)
                            {
                                break; // Goto next file only on success.
                            }
                        }
                    }
                }
            }
            finally
            {
                progress.DoClose();
            }
        }
示例#15
0
		/// <summary>
		/// Installs Ftp7 provider.
		/// </summary>
		/// <returns>Error messages.</returns>
        public override string[] Install()
        {
            List<string> messages = new List<string>();

			FtpSite site = null;
			string folder = FileUtils.EvaluateSystemVariables(DefaultFtpSiteFolder);
			string logsDirectory = FileUtils.EvaluateSystemVariables(DefaultFtpSiteLogsFolder);
			// Create site folder.
			if (!FileUtils.DirectoryExists(folder))
			{
				FileUtils.CreateDirectory(folder);
			}
			// Create logs folder.
			if (!FileUtils.DirectoryExists(logsDirectory))
			{
				FileUtils.CreateDirectory(logsDirectory);
			}

			site = new FtpSite();

			site.Name = this.SiteId;
			site.SiteId = this.SiteId;
			site.ContentPath = DefaultFtpSiteFolder;
			site.Bindings = new ServerBinding[1];
			// set default log directory
			site.LogFileDirectory = DefaultFtpSiteLogsFolder;
			// set default logging fields
			site[FtpSite.MSFTP7_LOG_EXT_FILE_FIELDS] = DEFAULT_LOG_EXT_FILE_FIELDS;

			if (!String.IsNullOrEmpty(this.SharedIP))
			{
				site.Bindings[0] = new ServerBinding(this.SharedIP, "21", String.Empty);
			}
			else
			{
				site.Bindings[0] = new ServerBinding("*", "21", "*");
				//// Get information on local server.
				//IPHostEntry localServerHostEntry = Dns.GetHostEntry(Dns.GetHostName());
				//foreach (IPAddress address in localServerHostEntry.AddressList)
				//{
				//    if (address.AddressFamily == AddressFamily.InterNetwork)
				//    {
				//        site.Bindings[0] = new ServerBinding(address.ToString(), "21", String.Empty);
				//    }
				//}
			}

			if (this.IsFtpServerBindingsInUse(site))
			{
				messages.Add("Cannot create ftp site because requested bindings are already in use.");
				return messages.ToArray();
			}

            try
            {
                SecurityUtils.EnsureOrganizationalUnitsExist(ServerSettings, UsersOU, GroupsOU);
            }
            catch (Exception ex)
            {
                messages.Add(String.Format("Could not check/create Organizational Units: {0}", ex.Message));
                return messages.ToArray();
            }

            // create folder if it not exists
            if (String.IsNullOrEmpty(SiteId))
            {
                messages.Add("Please, select FTP site to create accounts on");
            }
            else
            {
                // create FTP group name
                if (String.IsNullOrEmpty(FtpGroupName))
                {
                    messages.Add("FTP Group can not be blank");
                }
                else
                {
                    try
                    {
                        // create group
                        if (!SecurityUtils.GroupExists(FtpGroupName, ServerSettings, GroupsOU))
                        {
                            SystemGroup group = new SystemGroup();
                            group.Name = FtpGroupName;
                            group.Members = new string[] { };
                            group.Description = "WebsitePanel System Group";

                            SecurityUtils.CreateGroup(group, ServerSettings, UsersOU, GroupsOU);
                        }
                    }
                    catch (Exception ex)
                    {
                        messages.Add(String.Format("There was an error while adding '{0}' group: {1}",
                            FtpGroupName, ex.Message));
                        return messages.ToArray();
                    }
                }

            	if (!this.ftpSitesService.SiteExists(this.SiteId))
				{
						this.CreateSite(site);
				}
				else
				{
					this.UpdateSite(site);
				}
            	
                try
                {
                    // set permissions on the site root
					SecurityUtils.GrantNtfsPermissions(site.ContentPath, FtpGroupName,
						NTFSPermission.Read, true, true, ServerSettings,
						UsersOU, GroupsOU);
                }
                catch (Exception ex)
                {
                    messages.Add(String.Format("Can not set permissions on '{0}' folder: {1}",
                        site.ContentPath, ex.Message));
                    return messages.ToArray();
                }
            }
            return messages.ToArray();
        }
示例#16
0
		/// <summary>
		/// Gets a value which shows whether supplied site contains bindings that are already in use.
		/// </summary>
		/// <param name="site">Site to check.</param>
		/// <returns>true - if any of supplied bindinds is in use; false -otherwise.</returns>
		private bool IsFtpServerBindingsInUse(FtpSite site)
		{
			if (site == null)
			{
				throw new ArgumentNullException("site");
			}

			// check for server bindings
			foreach (FtpSite existentSite in this.GetSites())
			{
				if (existentSite.Name != site.Name)
				{
					foreach (ServerBinding usedBinding in existentSite.Bindings)
					{
						foreach (ServerBinding requestedBinding in site.Bindings)
						{
							if (usedBinding.IP == requestedBinding.IP && usedBinding.Port == usedBinding.Port)
							{
								return true;
							}
						}
					}
				}
			}
			return false;
		}
示例#17
0
		/// <summary>
		/// Checks if bindings listed in given site already in use.
		/// </summary>
		/// <param name="site">Site to check.</param>
		/// <exception cref="InvalidOperationException">Is thrown in case supplied site contains bindings that are already in use.</exception>
		private void CheckFtpServerBindings(FtpSite site)
		{
			if (this.IsFtpServerBindingsInUse(site))
			{
				throw new InvalidOperationException("Some of ftp site's bindings are already in use.");
			}
		}
示例#18
0
		/// <summary>
		/// Fills iis configuration with information from ftp site.
		/// </summary>
		/// <param name="ftpSite">Ftp site that holds information.</param>
		private void FillIisFromFtpSite(FtpSite ftpSite)
		{
			IisFtpSite iisFtpSite = this.ftpSitesService.GetIisFtpSite(ftpSite.SiteId);
			string logExtFileFields = ftpSite[FtpSite.MSFTP7_LOG_EXT_FILE_FIELDS];
			
			if (iisFtpSite != null)
			{
				// Security settings.
				iisFtpSite.Security.Authentication.AnonymousAuthentication.Enabled = ftpSite.AllowAnonymous;
				iisFtpSite.Security.Authentication.AnonymousAuthentication.UserName = ftpSite.AnonymousUsername;
				iisFtpSite.Security.Authentication.AnonymousAuthentication.Password = ftpSite.AnonymousUserPassword;
				// enable logging
				iisFtpSite.LogFile.Enabled = true;
				// set logging fields
				if (!String.IsNullOrEmpty(logExtFileFields))
					iisFtpSite.LogFile.LogExtFileFlags = (FtpLogExtFileFlags)Enum.Parse(typeof(FtpLogExtFileFlags), logExtFileFields);
				// set log files directory
				if (!String.IsNullOrEmpty(ftpSite.LogFileDirectory))
					iisFtpSite.LogFile.Directory = ftpSite.LogFileDirectory;
			}
			// Set new bindings.
			this.CheckFtpServerBindings(ftpSite);
			this.ftpSitesService.SetSiteBindings(ftpSite.Name, ftpSite.Bindings);
			// Physical path
			this.ftpSitesService.SetSitePhysicalPath(ftpSite.SiteId, "/", ftpSite.ContentPath);
		}
示例#19
0
		/// <summary>
		/// Creates ftp site.
		/// </summary>
		/// <param name="site">Ftp site to be created.</param>
		/// <returns>Created site id.</returns>
		/// <exception cref="ArgumentNullException">Is thrown in case supplied argument is null.</exception>
		/// <exception cref="ArgumentException">
		/// Is thrown in case site id or its name is null or empty or if site id is not equal to default ftp site name.
		/// </exception>
        public string CreateSite(FtpSite site)
        {
			if (site == null)
			{
				throw new ArgumentNullException("site");
			}

			if (String.IsNullOrEmpty(site.SiteId) || String.IsNullOrEmpty(site.Name))
			{
				throw new ArgumentException("Site id or name is null or empty.");
			}

			this.CheckFtpServerBindings(site);

			PropertyBag siteBag = this.ftpSitesService.GetSiteDefaults();
			// Set site name
			siteBag[FtpSiteGlobals.Site_Name] = site.Name;
			// Set site physical path
			siteBag[FtpSiteGlobals.VirtualDirectory_PhysicalPath] = site.ContentPath;
			PropertyBag ftpBinding = new PropertyBag();
			// Set site binding protocol
			ftpBinding[FtpSiteGlobals.BindingProtocol] = "ftp";
			// fill binding summary info
			ftpBinding[FtpSiteGlobals.BindingInformation] = site.Bindings[0].ToString();

			// Set site binding
			siteBag[FtpSiteGlobals.Site_SingleBinding] = ftpBinding;

			// Auto-start
			siteBag[FtpSiteGlobals.FtpSite_AutoStart] = true;

			// Set anonumous authentication
			siteBag[FtpSiteGlobals.Authentication_AnonymousEnabled] = true;
			siteBag[FtpSiteGlobals.Authentication_BasicEnabled] = true;

			this.ftpSitesService.AddSite(siteBag);

			AuthorizationRuleCollection rules =  this.ftpSitesService.GetAuthorizationRuleCollection(site.Name);
			rules.Add(AuthorizationRuleAccessType.Allow, "*", String.Empty, PermissionsFlags.Read);

			IisFtpSite iisFtpSite = this.ftpSitesService.GetIisFtpSite(site.Name);
			iisFtpSite.UserIsolation.Mode = Mode.StartInUsersDirectory;
			iisFtpSite.Security.Ssl.ControlChannelPolicy = ControlChannelPolicy.SslAllow;
			iisFtpSite.Security.Ssl.DataChannelPolicy = DataChannelPolicy.SslAllow;

			this.FillIisFromFtpSite(site);

			this.ftpSitesService.CommitChanges();

			// Do not start the site because it is started during creation.
			try
			{
				this.ChangeSiteState(site.Name, ServerState.Started);
			}
			catch
			{
				// Ignore the error if happened.
			}
			return site.Name;
        }
示例#20
0
		/// <summary>
		/// Gets ftp site with given name.
		/// </summary>
		/// <param name="siteId">Ftp site's name to get.</param>
		/// <returns>Ftp site.</returns>
		/// <exception cref="ArgumentException"> Is thrown in case site name is null or empty. </exception>
		public FtpSite GetSite(string siteId)
        {
			if (String.IsNullOrEmpty(siteId))
			{
				throw new ArgumentException("Site name is null or empty.");
			}

            FtpSite ftpSite = new FtpSite();
			ftpSite.SiteId = siteId;
			ftpSite.Name = siteId;
			this.FillFtpSiteFromIis(ftpSite);
			
			return ftpSite;
        }
示例#21
0
		/// <summary>
		/// Updates site with given information.
		/// </summary>
		/// <param name="site">Ftp site.</param>
        public void UpdateSite(FtpSite site)
        {
			// Check server bindings.
			CheckFtpServerBindings(site);

			this.FillIisFromFtpSite(site);

			this.ftpSitesService.CommitChanges();
        }
示例#22
0
        private void StartFtpDeleteInThread()
        {
            try
            {
                Thread.Sleep(50);

                String host     = folder.Site.host;
                String username = folder.Site.username;
                String pwd      = folder.Site.pwd;



                String targetfolder = folder.Path;

                if (files != null)
                {
                    int count      = files.Count();
                    int iFileCount = 0;


                    foreach (var file in files)
                    {
                        string basicProgress = (++iFileCount).ToString() + " of " + count.ToString() + " : " + file;

                        progress.SetProgress(basicProgress);
                        if (this.cancelled)
                        {
                            break;
                        }

                        FtpWebResponse response = null;

                        while (!this.cancelled)
                        {
                            bool      success       = false;
                            Exception lastException = null;

                            for (int i = 0; i < 4 && !this.cancelled; i++)
                            {
                                try
                                {
                                    progress.SetProgress(basicProgress + " - Connecting");

                                    lock (FtpSite.LockInstance())
                                    {
                                        string        ftpfullpath = "ftp://" + host + targetfolder + "/" + file;
                                        FtpWebRequest ftp         = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);

                                        ftp.UseBinary = true;
                                        ftp.KeepAlive = true;
                                        ftp.Method    = WebRequestMethods.Ftp.DeleteFile;
                                        ftp.Timeout   = 2000;

                                        ftp.Credentials = new NetworkCredential(username, pwd);

                                        response = (FtpWebResponse)ftp.GetResponse();

                                        progress.SetProgress(basicProgress + response.StatusDescription);
                                        success = true;
                                    }
                                    break;
                                }
                                catch (Exception e)
                                {
                                    lastException = e;
                                }
                                finally
                                {
                                    try { if (response != null)
                                          {
                                              response.Close();
                                          }
                                    }
                                    catch (Exception) { }
                                }
                            }
                            if (this.cancelled)
                            {
                                return;
                            }

                            if (!success)
                            {
                                DialogResult keepGoing = MessageBox.Show("Keep Trying? Failed after 4 attempts to delete: "
                                                                         + file + " Exception: " + lastException.Message
                                                                         , "FTP Failure"
                                                                         , MessageBoxButtons.OKCancel
                                                                         , MessageBoxIcon.Error
                                                                         , MessageBoxDefaultButton.Button1);

                                if (keepGoing != DialogResult.OK)
                                {
                                    return; // Don't true any more.
                                }
                            }

                            if (success)
                            {
                                break; // Goto next file only on success.
                            }
                        }
                    }
                }
            }
            finally
            {
                progress.DoClose();
            }
        }
示例#23
0
        public static void DeserializeFtpSiteProperties(FtpSite ftpSite, PropertyBag bag)
        {
            foreach (int num in bag.ModifiedKeys)
            {
                switch (num)
                {
                case FtpSiteGlobals.Connections_UnauthenticatedTimeout:
                    ftpSite.Connections.UnauthenticatedTimeout = (int)bag[num];
                    break;

                case FtpSiteGlobals.Connections_ControlChannelTimeout:
                    ftpSite.Connections.ControlChannelTimeout = (int)bag[num];
                    break;

                case FtpSiteGlobals.Connections_DisableSocketPooling:
                    ftpSite.Connections.DisableSocketPooling = (bool)bag[num];
                    break;

                case FtpSiteGlobals.Connections_ServerListenBacklog:
                    ftpSite.Connections.ServerListenBacklog = (int)bag[num];
                    break;

                case FtpSiteGlobals.Connections_DataChannelTimeout:
                    ftpSite.Connections.DataChannelTimeout = (int)bag[num];
                    break;

                case FtpSiteGlobals.Connections_MinBytesPerSecond:
                    ftpSite.Connections.MinBytesPerSecond = (int)bag[num];
                    break;

                case FtpSiteGlobals.Connections_MaxConnections:
                    ftpSite.Connections.MaxConnections = (long)bag[num];
                    break;

                case FtpSiteGlobals.Connections_ResetOnMaxConnection:
                    ftpSite.Connections.ResetOnMaxConnections = (bool)bag[num];
                    break;

                case FtpSiteGlobals.Ssl_ServerCertHash:
                    ftpSite.Security.Ssl.ServerCertHash = (string)bag[num];
                    break;

                case FtpSiteGlobals.Ssl_ControlChannelPolicy:
                    ftpSite.Security.Ssl.ControlChannelPolicy = (ControlChannelPolicy)bag[num];
                    break;

                case FtpSiteGlobals.Ssl_DataChannelPolicy:
                    ftpSite.Security.Ssl.DataChannelPolicy = (DataChannelPolicy)bag[num];
                    break;

                case FtpSiteGlobals.Authentication_AnonymousEnabled:
                    ftpSite.Security.Authentication.AnonymousAuthentication.Enabled = (bool)bag[num];
                    break;

                case FtpSiteGlobals.Authentication_BasicEnabled:
                    ftpSite.Security.Authentication.BasicAuthentication.Enabled = (bool)bag[num];
                    break;

                case FtpSiteGlobals.FtpSite_AutoStart:
                    ftpSite.ServerAutoStart = (bool)bag[num];
                    break;
                }
            }
        }
示例#24
0
    	/// <summary>
		/// Fills ftp site with data from iis ftp site.
		/// </summary>
		/// <param name="ftpSite">Ftp site to fill.</param>
		private void FillFtpSiteFromIis(FtpSite ftpSite)
		{
			IisFtpSite iisFtpSite = this.ftpSitesService.GetIisFtpSite(ftpSite.SiteId);
			if (iisFtpSite != null)
			{
				// Security settings.
				ftpSite.AllowAnonymous = iisFtpSite.Security.Authentication.AnonymousAuthentication.Enabled;
				ftpSite.AnonymousUsername = iisFtpSite.Security.Authentication.AnonymousAuthentication.UserName;
				ftpSite.AnonymousUserPassword = iisFtpSite.Security.Authentication.AnonymousAuthentication.Password;
				// Logging settings.
				ftpSite[FtpSite.MSFTP7_SITE_ID] = iisFtpSite.SiteServiceId;
				if (iisFtpSite.LogFile.Enabled)
				{
					ftpSite.LogFileDirectory = iisFtpSite.LogFile.Directory;
					ftpSite[FtpSite.MSFTP7_LOG_EXT_FILE_FIELDS] = iisFtpSite.LogFile.LogExtFileFlags.ToString();
				}
			}
			// Bindings
			ftpSite.Bindings = this.ftpSitesService.GetSiteBindings(ftpSite.SiteId);
			// Physical path
			ftpSite.ContentPath = this.ftpSitesService.GetSitePhysicalPath(ftpSite.SiteId, "/");
		}