Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            FtpClient myFtp = new FtpClient(@"127.0.0.1", @"", @"");
            myFtp.Login();
            string[] files = myFtp.GetFileList();
            myFtp.Download(files[0], string.Format(@"C:\{0}", files[0]));
            //myFtp.BeginGetFileList(new AsyncCallback(delegate(IAsyncResult iar) {
            //    foreach (string key in (iar.AsyncState as eTerm.AsyncSDK.FtpClient.GetFileListCallback).EndInvoke(iar)) {
            //        myFtp.BeginDownload(key, new AsyncCallback(delegate(IAsyncResult iar1) {
            //            Console.WriteLine(@"Download        {0}", key);
            //        }));
            //    }
            //    iar.AsyncWaitHandle.Close();
            //}));

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// SVRs the update.
        /// </summary>
        private void SvrUpdate()
        {
            string SvrVersionFile = @"Version.Xml";
            DirectoryInfo SvrPath = new DirectoryInfo(@".\");
            FileInfo VersionFile = new FileInfo(string.Format(@"{0}{1}", SvrPath.FullName, SvrVersionFile));
            Version AppVersion = null;
            try
            {
                AppVersion = GetAppVersion();
                FtpClient SvrFtp = new FtpClient(AsyncStackNet.Instance.ASyncSetup.CoreServer, string.Empty, string.Empty);
                SvrFtp.Login();
                SvrFtp.Download(SvrVersionFile, string.Format(@"{0}{1}", SvrPath.FullName, SvrVersionFile));
                if (AppVersion.Equals(GetAppVersion()))
                {
                    UpdateStatusText(stripSvrUpdate, string.Format(@"无可用更新!",@""));
                    return;
                }
                UpdateStatusText(stripSvrUpdate, string.Format(@"发现更新,新版本号为:{0}", GetAppVersion().ToString()));

                XElement root = XElement.Load(new FileInfo(string.Format(@"{0}{1}", SvrPath.FullName, SvrVersionFile)).FullName);
                DirectoryInfo UpdateFolder= new DirectoryInfo(string.Format(@"{0}{1}\", SvrPath.FullName, @"SvrUpdate"));
                if (!UpdateFolder.Exists) UpdateFolder.Create();
                List<XElement> svrItems = root.Element(@"SvrFiles").Elements(@"Item").ToList<XElement>();
                SvrUpdateMaxQueuen(svrItems.Count);
                int SvrIndex=0;
                foreach (XElement element in svrItems)
                {
                    try {
                        SvrFtp.Download(element.Value, string.Format(@"{0}{1}", UpdateFolder.FullName, element.Value),true);
                        SvrUpdateCurrentQueuen(++SvrIndex);
                        UpdateStatusText(stripSvrUpdate, string.Format(@"更新{0}完成!", element.Value));
                    }
                    catch(Exception ex) {
                        UpdateStatusText(stripSvrUpdate, string.Format(@"更新{0}异常:{1}",element.Value, ex.Message));
                    }
                }
                UpdateStatusText(stripSvrUpdate, string.Format(@"文件更新完成,下次重启服务后将生效!", @""));
                //new System.Threading.Timer(delegate {
                //    Application.Exit();
                //    Application.Restart();
                //},null, 5000, 0);
                SvrFtp.Close();
            }
            catch(Exception ex) {
                UpdateStatusText(stripSvrUpdate, string.Format(@"更新发生异常:{0}", ex.Message));
                __SvrUpdateInterval.Dispose();
            }
        }