Beispiel #1
0
        /// <summary>
        /// 원본 폴더의 모든 파일과 폴더(하위 폴더 포함)를 대상 폴더에 복사함.
        /// </summary>
        /// <param name="FolderSrc">원본 폴더</param>
        /// <param name="FolderDest">대상 폴더</param>
        /// <example>
        /// 다음은 D:\Temp 폴더의 값을 모든 파일, 폴더를 D:\Temp2로 복사함.
        /// 그러나 확장자가 bat인 파일은 복사가 취소됨.
        /// <code>
        /// static void Main(string[] args)
        /// {
        ///	 CFile f = new CFile();
        ///	 //파일 복사 전에 발생하는 이벤트
        ///	 f.BeforeFileUpload += new CFile.BeforeFileUploadEventHandler(f_BeforeFileUpload);
        ///	 f.CopyDirectory(@"D:\Temp\log", @"D:\Temp2\log");
        /// }
        ///
        /// private static void f_BeforeFileUpload(string FullPathSrc, ref bool Cancel)
        /// {
        ///	 if (FullPathDest.EndsWith(".bat"))
        ///	 {
        ///		 //파일의 복사를 취소함.
        ///		 Cancel = true;
        ///	 }
        /// }
        /// </code>
        /// </example>
        public void UploadDirectory(string FolderLocal, string FolderRemote)
        {
            if (this.BeforeDirectoryUpload != null)
            {
                CBeforeDirectoryUploadEventArgs e = new CBeforeDirectoryUploadEventArgs()
                {
                    LocalFolder = FolderLocal
                };
                this.BeforeDirectoryUpload(this, e);

                if (e.Cancel)
                {
                    return;
                }
            }

            string[] aFiles = null;

            if (!FolderRemote.EndsWith("/"))
            {
                FolderRemote += '/';
            }

            try
            {
                //D:\System Volume Information의 경우는 액세스할 수 없다는 에러가 나므로 무시함.
                aFiles = Directory.GetFileSystemEntries(FolderLocal);
            }
            catch (Exception)
            {
                return;
            }

            bool IsDirectoryChecked = false;

            foreach (string LocalFullPath in aFiles)
            {
                if (Directory.Exists(LocalFullPath))
                {
                    this.UploadDirectory(LocalFullPath, FolderRemote + Path.GetFileName(LocalFullPath));
                }
                else
                {
                    if (!IsDirectoryChecked)
                    {
                        if (!this.DirectoryExists(FolderRemote))
                        {
                            this.CreateDirectory(FolderRemote);
                        }

                        IsDirectoryChecked = true;
                    }

                    string RemoteFullUrl = FolderRemote + Path.GetFileName(LocalFullPath);
                    this.UploadFile(LocalFullPath, RemoteFullUrl);
                }
            }
        }
Beispiel #2
0
        private void ftp_BeforeDirectoryUpload(object sender, CBeforeDirectoryUploadEventArgs e)
        {
            FileInfo fiSrc = new FileInfo(e.LocalFolder);
            //FTP에 있는 파일은 원래 파일 날짜가 아닌 업로드된 파일의 날짜 정보를 가지므로
            //날짜를 비교할 수 없으므로 원본파일의 날짜만 기준이 되므로 null로 설정함.
            FileInfo fiDest = null;

            string FullPathSrcNewIs;

            if (!IsValidForSync(fiSrc, fiDest, true, out FullPathSrcNewIs))
            {
                e.Cancel = true;
            }
        }