在 C# 中从 FTP 中删除文件

编程入门 行业动态 更新时间:2024-10-25 06:31:25
本文介绍了在 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 中删除文件

本文发布于:2023-11-07 22:35:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567624.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   FTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!