gpt4 book ai didi

c# - 在 C# 中从 FTP 中删除文件

转载 作者:可可西里 更新时间:2023-11-01 07:59:37 28 4
gpt4 key购买 nike

我的程序可以使用以下代码将文件上传到 FTP 服务器:

WebClient client = new WebClient();
client.Credentials = new System.Net.NetworkCredential(ftpUsername, ftpPassword);
client.BaseAddress = ftpServer;
client.UploadFile(fileToUpload, WebRequestMethods.Ftp.UploadFile, fileName);

现在我需要删除一些文件,但我做不到。我应该用什么代替

client.UploadFile(fileToUpload, WebRequestMethods.Ftp.UploadFile, fileName);

最佳答案

您需要使用 FtpWebRequest类做那个,我想。

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# - 在 C# 中从 FTP 中删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17617203/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com