コード例 #1
0
        /// <summary>
        /// ftp測試連線
        /// </summary>
        public void FTP_TryConnection(ref ftpClient ftpclient)
        {
            #region 取得要連結到的FTP IP
            Step = "取得ftpIP";
            DataTable dt_LCUIPList = GetIPList();
            if (dt_LCUIPList.Rows.Count <= 0)
            {
                throw new Exception("無法取得ftp IP");
            }
            #endregion

            DataRow dr_LCUIPList = dt_LCUIPList.Rows[0];
            string  DEVICE_IP    = dr_LCUIPList[0].ToString();

            #region 設定ftp連線
            Step = "設定ftp";

            //連結ftp
            ftpclient = new ftpClient(@"ftp://" + DEVICE_IP + @":21/", "anonymous", "anonymous");

            //測試連線是否正常
            ftpclient.directoryListSimple(@"/");

            //建立暫存檔資料夾
            string FileDirectory = System.AppDomain.CurrentDomain.BaseDirectory + Parameter_DEVICE_AREA + @"\" + Parameter_DEVICE_ID;
            Directory.CreateDirectory(FileDirectory);
            #endregion
        }
コード例 #2
0
        /// <summary>
        /// ftp測試連線
        /// </summary>
        public void FTP_TryConnection(ref ftpClient ftpclient)
        {
            #region 設定ftp連線
            Step = "設定ftp";

            //連結ftp
            ftpclient = new ftpClient(@"ftp://" + Parameter_DEVICE_IP + @":21/", "anonymous", "anonymous");

            //測試連線是否正常
            ftpclient.directoryListSimple(@"/");
            Agent_WriteLog("PC<->" + Parameter_DEVICE_ID + " " + Parameter_DEVICE_IP);

            //建立暫存檔資料夾
            string FileDirectory = System.AppDomain.CurrentDomain.BaseDirectory + Parameter_DEVICE_AREA + @"\" + Parameter_DEVICE_ID;
            Directory.CreateDirectory(FileDirectory);
            #endregion
        }
コード例 #3
0
        /// <summary>
        /// 檢查檔案上傳是否完成
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="ftp"></param>
        /// <param name="ExistType">0:檔案要存在 1:檔案要不存在</param>
        /// <returns></returns>
        public string FTPCheckFileUploadOK(string FileName, ref ftpClient ftp, int ExistType)
        {
            bool IsOK        = false;
            int  CheckSecond = 0;
            int  MaxSeconds  = 30;

            string[] files;

            //第一關:檢查檔案存在
            //如果是要檢查檔案消失的設定, 有可能檔案下傳後馬上消失, 來不及先進入第一關的確認檔案存在
            try
            {
                IsOK = false;

                while (true)
                {
                    //CheckFileSize = ftp.getFileSize(FileName);
                    //CheckSecond = MaxWaitSecond + 1;
                    //Steps = 1;

                    files = ftp.directoryListSimple("");
                    foreach (string file in files)
                    {
                        if (file == FileName)
                        {
                            IsOK = true;
                            break;
                        }
                    }

                    if (IsOK)
                    {
                        break;
                    }

                    if (ExistType == 1)
                    {
                        if (CheckSecond >= MaxSeconds)
                        {
                            break;
                        }
                    }

                    Thread.Sleep(1000);
                    CheckSecond       += 1;
                    Console.CursorLeft = 0;
                    Console.Write(CheckSecond.ToString() + "...");
                }
                Console.WriteLine("");

                //第二關:檔案要消失, 才能離開
                if (ExistType == 1)
                {
                    while (true)
                    {
                        IsOK  = true;
                        files = ftp.directoryListSimple("");

                        foreach (string file in files)
                        {
                            if (file == FileName)
                            {
                                IsOK = false;
                            }
                        }

                        if (IsOK)
                        {
                            break;
                        }

                        Thread.Sleep(1000);
                        CheckSecond       += 1;
                        Console.CursorLeft = 0;
                        Console.Write(CheckSecond.ToString() + "...");
                    }
                    Console.WriteLine("");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            #region 檔案下傳時間寫入log
            string strlog = " 下傳 " + FileName;
            if (ExistType == 1)
            {
                strlog += " 並等待消失.";
            }
            strlog += " 共花費:" + CheckSecond.ToString() + " 秒";
            Agent_WriteLog(strlog);
            #endregion

            Console.WriteLine("");
            return("");
        }