本文介绍了在 C# 中从 FTP 中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的程序可以使用以下代码将文件上传到 FTP 服务器:
My program can upload files into an FTP server using this code:
WebClient client = new WebClient(); client.Credentials = new System.Net.NetworkCredential(ftpUsername, ftpPassword); client.BaseAddress = ftpServer; client.UploadFile(fileToUpload, WebRequestMethods.Ftp.UploadFile, fileName);现在我需要删除一些文件,但我做不到.我应该用什么来代替
Right now I need to delete some files and I can't do that right. What should I use instead of
client.UploadFile(fileToUpload, WebRequestMethods.Ftp.UploadFile, fileName); 推荐答案您需要使用 FtpWebRequest 类来做那个,我想.
You'll need to use the FtpWebRequest class to do that one, I think.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); //If you need to use network credentials request.Credentials = new NetworkCredential(ftpUsername, ftpPassword); //additionally, if you want to use the current user's network credentials, just use: //System.Net.CredentialCache.DefaultNetworkCredentials request.Method = WebRequestMethods.Ftp.DeleteFile; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Console.WriteLine("Delete status: {0}", response.StatusDescription); response.Close();更多推荐
在 C# 中从 FTP 中删除文件
发布评论