Deleting file from FTP in C#

后端 未结 4 977
小蘑菇
小蘑菇 2020-12-31 04:15

My program can upload files into an FTP server using this code:

WebClient client = new WebClient();
client.Credentials = new System.Net.NetworkCredential(ftp         


        
4条回答
  •  悲&欢浪女
    2020-12-31 05:07

    You should use FtpWebRequest when you need to delete files:

    // Get the object used to communicate with the server.
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
    request.Method = WebRequestMethods.Ftp.DeleteFile;
    
    FtpWebResponse response = (FtpWebResponse) request.GetResponse();
    Console.WriteLine("Delete status: {0}",response.StatusDescription);  
    response.Close();
    

    ref: http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx

提交回复
热议问题