예제 #1
0
        /// <summary>
        /// Convenience method, so that we don't open a new connection when using this
        /// method from within another method.
        /// </summary>
        /// <remarks>
        /// Convenience method, so that we don't open a new connection when using this
        /// method from within another method. Otherwise every API invocation incurs
        /// the overhead of opening/closing a TCP connection.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        private bool Delete(FTPClient client, Path file, bool recursive)
        {
            Path   workDir  = new Path(client.PrintWorkingDirectory());
            Path   absolute = MakeAbsolute(workDir, file);
            string pathName = absolute.ToUri().GetPath();

            try
            {
                FileStatus fileStat = GetFileStatus(client, absolute);
                if (fileStat.IsFile())
                {
                    return(client.DeleteFile(pathName));
                }
            }
            catch (FileNotFoundException)
            {
                //the file is not there
                return(false);
            }
            FileStatus[] dirEntries = ListStatus(client, absolute);
            if (dirEntries != null && dirEntries.Length > 0 && !(recursive))
            {
                throw new IOException("Directory: " + file + " is not empty.");
            }
            foreach (FileStatus dirEntry in dirEntries)
            {
                Delete(client, new Path(absolute, dirEntry.GetPath()), recursive);
            }
            return(client.RemoveDirectory(pathName));
        }
        void DeleteOtherFiles(IEnumerable <string> files, string version, bool ftp = false)
        {
            List <string> lst          = new List <string>();
            FTPClient     cl           = null;
            string        pathOnServer = null;

            if (ftp)
            {
                cl           = GetFTPClient();
                pathOnServer = envAccessor.CurrentEnvironment.Upload.PathOnServer;
            }

            foreach (var f in files)
            {
                if (!f.Contains(version) && !f.Contains("-dev"))
                {
                    WriteFileOperation("Deleting", Path.GetFileName(f), false);

                    try
                    {
                        if (ftp)
                        {
                            var url = Utils.CombineUrl(pathOnServer, BundleFolder, f);
                            cl.DeleteFile(url);
                        }
                        else
                        {
                            File.Delete(f);
                        }

                        WriteSuccess();
                    }
                    catch (Exception ex)
                    {
                        WriteFailed(null, new Result {
                            Message = ex.Message
                        });
                    }
                    Out.WriteLine();
                }
            }
        }
예제 #3
0
        private void menuDelete_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
            string            name     = menuItem.Tag.ToString();

            ftpClient.RelatePath = string.Format("{0}/{1}", ftpClient.RelatePath, name);
            bool isOk = false;

            ftpClient.DeleteFile(out isOk);
            ftpClient.SetPrePath();
            if (isOk)
            {
                ShowFilesDirectory();
                lblMsg.Text = "删除成功";
            }
            else
            {
                lblMsg.Text = "删除失败";
            }
        }