예제 #1
0
        /// <summary>
        ///	删除文件
        /// </summary>
        /// <param name="fileName"></param>
        public void DeleteFile(string fileName)
        {
            FtpConnection ftp = this.FtpConn();

            try
            {
                ftp.DeleteFile(fileName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                ftp.Close();
            }
        }
예제 #2
0
        /// <summary>
        /// Delete given files from the FTP Directory
        /// </summary>
        private void DeleteFiles()
        {
            if (this.FileNames == null)
            {
                this.Log.LogError("The required FileNames attribute has not been set for FTP.");
                return;
            }

            using (FtpConnection ftpConnection = this.CreateFtpConnection())
            {
                ftpConnection.LogOn();
                this.LogTaskMessage("Deleting Files");
                if (!string.IsNullOrEmpty(this.RemoteDirectoryName))
                {
                    this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Setting Current Directory: {0}", this.RemoteDirectoryName));
                    ftpConnection.SetCurrentDirectory(this.RemoteDirectoryName);
                }

                foreach (string fileName in this.FileNames.Select(item => item.ItemSpec))
                {
                    try
                    {
                        this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Deleting: {0}", fileName));
                        ftpConnection.DeleteFile(fileName);
                    }
                    catch (FtpException ex)
                    {
                        if (ex.Message.Contains("550"))
                        {
                            continue;
                        }

                        this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "There was an error in deleting file: {0}. The Error Details are \"{1}\" and error code is {2} ", fileName, ex.Message, ex.ErrorCode));
                    }
                }
            }
        }