Delete File On Server

How do you delete a file on the server using WebRequestMethods.Ftp.DeleteFile?

Please provide example code.

Thanks
Ray TurnerSenior ConsultantAsked:
Who is Participating?
 
Tapan PattanaikConnect With a Mentor Senior EngineerCommented:
Hi rgturner ,


public static bool DeleteFilesOnServer(Uri serverUri)
{
    // The serverUri parameter should use the ftp:// scheme.
    // It contains the name of the server file that is to be deleted.
    // Example: ftp://contoso.com/someFile.txt.
    //  

    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // 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();
     response.Close();
    return true;
}
0
 
Ray TurnerSenior ConsultantAuthor Commented:
Thanks!  That was excellent!
0
All Courses

From novice to tech pro — start learning today.