예제 #1
0
        /// <summary>
        /// Executes the specified result.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        protected override bool Execute(IIntegrationResult result)
        {
            var relativeLocalFolder = result.BaseFromWorkingDirectory(this.LocalFolderName);

            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : GetDescription(relativeLocalFolder));

            string remoteFolder = FtpFolderName;
            FtpLib ftp          = new FtpLib(this, result.BuildProgressInformation);


            try
            {
                ftp.LogIn(ServerName, UserName, Password, UseActiveConnectionMode);

                ftp.TimeDifference = new TimeSpan(TimeDifference, 0, 0);



                if (!FtpFolderName.StartsWith("/"))
                {
                    remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName);
                }

                if (Action == FtpAction.UploadFolder)
                {
                    Log.Debug("Uploading {0} to {1}, recursive : {2}", relativeLocalFolder, remoteFolder, RecursiveCopy);
                    ftp.UploadFolder(remoteFolder, relativeLocalFolder, RecursiveCopy);
                }

                if (Action == FtpAction.DownloadFolder)
                {
                    Log.Debug("Downloading {0} to {1}, recursive : {2}", remoteFolder, relativeLocalFolder, RecursiveCopy);
                    ftp.DownloadFolder(relativeLocalFolder, remoteFolder, RecursiveCopy);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                // try to disconnect in a proper way on getting an error
                try
                {      // swallow exception on disconnect to keep the original error
                    if (ftp.IsConnected())
                    {
                        ftp.DisConnect();
                    }
                }
                catch { }
                Log.Info("throwing");
                throw;
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Gets the modifications.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            ftp = new FtpLib(to.BuildProgressInformation);
            string remoteFolder = FtpFolderName;

            ftp.LogIn(ServerName, UserName, Password.PrivateValue, UseActiveConnectionMode);

            if (!FtpFolderName.StartsWith("/"))
            {
                remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName);
            }

            Modification[] mods = ftp.ListNewOrUpdatedFilesAtFtpSite(LocalFolderName, remoteFolder, RecursiveCopy);

            ftp.DisConnect();

            return(mods);
        }
예제 #3
0
        private ScanAction(DirectoryInfo appPath)
        {
            config = new ConfigSettings();

            FileInfo configFile = new FileInfo(appPath + "\\" + ConfigFileName);

            if (!configFile.Exists)
            {
                throw new Exception("配置文件不存在! " + configFile.FullName);
            }

            NameValueCollection appSettings = new NameValueCollection();
            XmlDocument         dom         = new XmlDocument();

            dom.Load(configFile.FullName);
            XmlNodeList appSettingList = dom.SelectNodes("//appSettings/add");

            foreach (XmlNode node in appSettingList)
            {
                appSettings.Add(node.Attributes["key"].Value, node.Attributes["value"].Value);
            }

            config.FtpHost          = appSettings["FtpHost"];
            config.FtpUsername      = appSettings["FtpUsername"];
            config.FtpPassword      = appSettings["FtpPassword"];
            config.FtpUpload        = appSettings["FtpUpload"];
            config.LocalPath        = appSettings["LocalPath"];
            config.ArchiveDirectory = appSettings["ArchiveDirectory"];
            long periodInterval = 600;

            Int64.TryParse(appSettings["ScanPeriod"], out periodInterval);
            config.ScanPeriod = periodInterval;
            int lifeDay = 1;

            Int32.TryParse(appSettings["ArchiveLife"], out lifeDay);
            config.ArchiveLife = lifeDay;

            ftpClient = new FtpLib(config.FtpHost, config.FtpUsername, config.FtpPassword);

            DirectoryInfo logDir = new DirectoryInfo(appPath.FullName + "\\" + "logs");

            logger = SimplifiedLogger.Singleton(logDir);
        }
예제 #4
0
        /// <summary>
        /// Gets the source.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <remarks></remarks>
        public override void GetSource(IIntegrationResult result)
        {
            Util.Log.Info(result.HasModifications().ToString(CultureInfo.CurrentCulture));


            ftp = new FtpLib(result.BuildProgressInformation);
            string remoteFolder = FtpFolderName;

            ftp.LogIn(ServerName, UserName, Password.PrivateValue, UseActiveConnectionMode);


            if (!FtpFolderName.StartsWith("/"))
            {
                remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName);
            }

            ftp.DownloadFolder(LocalFolderName, remoteFolder, RecursiveCopy);

            ftp.DisConnect();
        }