我的程序可以使用以下代码将文件上传到 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 中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!