Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 104
  • Last Modified:

Delete File On Server

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

Please provide example code.

Thanks
0
Ray Turner
Asked:
Ray Turner
1 Solution
 
Tapan PattanaikSenior 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

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now