日期:2014-05-18  浏览次数:21041 次

如何删除Ftp主机上的文件
我要通过代码删除Ftp主机上的某个或某些文件 
ftpWebRequest.Method = WebRequestMethods.Ftp.DeleteFile;
往下怎么些呀


------解决方案--------------------
C# code
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="cred">通行证</param>
        /// <returns></returns>
        public static bool FtpDeleteFile(string path, ICredentials cred)
        {
            FtpWebRequest req = (FtpWebRequest)WebRequest.Create(path);
            if (cred != null)
                req.Credentials = cred;
            req.Method = WebRequestMethods.Ftp.DeleteFile;
            req.KeepAlive = false;

            try
            {
                req.GetResponse().Close();
                return true;
            }
            catch (WebException ex)
            {
                log.Error("FtpDeleteFile Error:" + ex.Message);
                return false;
            }
        }

------解决方案--------------------
去下载个FTPclient的类.
就是一个类文件.很好用的.
里边提供了很多方法.包括你所要的删除