Beispiel #1
0
        /// <summary>
        /// 删除文件夹(文件夹不为空)
        /// </summary>
        /// <param name="sFolderName">文件夹名称</param>
        /// <param name="SFTPPath">FTP服务器路径</param>
        public virtual void DeleteFtpDirWithAll(string sFolderName, bool isDeleteFolder = true)
        {
            try
            {
                //EACTSYSLOG.EACTSYSLOG.EactTrace("DeleteFtpDirWithAll", sFolderName);
                GetDirectoryList(sFolderName).ToList().ForEach(u =>
                {
                    DeleteFtpDirWithAll(Combine(sFolderName, u), true);
                });

                GetFileList(sFolderName).ToList().ForEach(u =>
                {
                    var file = Combine(sFolderName, u);
                    //EACTSYSLOG.EACTSYSLOG.EactTrace("DeleteFile", file);
                    Delete(file);
                });

                if (isDeleteFolder)
                {
                    //EACTSYSLOG.EACTSYSLOG.EactTrace("DeleteDirectory", sFolderName);
                    ftpConnection.RemoveDirectory(sFolderName);
                }
            }
            catch
            {
                throw;
            }
        }
Beispiel #2
0
        public void ClearFtp(FtpConnection ftp, string directory)
        {
            ftp.SetCurrentDirectory(directory);
            var dirs = ftp.GetDirectories();

            foreach (var dir in dirs)
            {
                if ((dir.Name != ".") && (dir.Name != ".."))
                {
                    ClearFtp(ftp, dir.Name); //Recursive call
                    ftp.RemoveDirectory(dir.Name);
                }
            }

            foreach (var file in ftp.GetFiles())
            {
                ftp.RemoveFile(file.Name);
            }

            if (ftp.GetCurrentDirectory() != "/")
            {
                ftp.SetCurrentDirectory("..");
            }
        }