Delete Files in Other Server

Last post 01-22-2008 2:59 AM by kipo. 2 replies.

Sort Posts:

  • Delete Files in Other Server

    01-22-2008, 2:07 AM

    I have 2 servers.

    1. Application Server - Microsoft Based (It contains all aspx, cs and other files)

    2. Media Server - Linux Based (It contains the downloadable materials, like mp3, pdf, zip, mpge files)

    Now I want to delete some files from Media Server using Asp.net web form on Application Server.

    Can anyone tell me how to do this.

  • Re: Delete Files in Other Server

    01-22-2008, 2:39 AM
    • Member
      495 point Member
    • rabeehabla
    • Member since 07-19-2007, 11:59 AM
    • Lebanon
    • Posts 77

    Hi, I do not know of a direct way, what you can do is create a program or web script hosted on Unix, and has the required security to delete files, and you can call it from asp.net.

     

    Regards

    Rabeeh Abla 

    Rabeeh Abla
    Software Architect
    GlobalVision

    Check my blog: http://weblogs.asp.net/rabeehabla/

    P.S: For answers that satisfy your question goal, you may mark as Answer.
  • Re: Delete Files in Other Server

    01-22-2008, 2:59 AM
    Answer
    • Star
      13,912 point Star
    • kipo
    • Member since 07-20-2006, 3:10 AM
    • Croatia
    • Posts 2,385

    First, create this class withinn App_Code folder (put values for username and password according to your media server):

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net;

    /// <summary>
    /// Summary description for FTPClass
    /// </summary>
    public class FTPClass
    {
        public static void Delete(string FileUrl)
        {
            FtpWebRequest reqObj = (FtpWebRequest)WebRequest.Create(FileUrl);
            reqObj.Method = WebRequestMethods.Ftp.DeleteFile;
            reqObj.Credentials = new NetworkCredential("username", "password");
            reqObj.GetResponse();
            reqObj = null;
        }
    }

    And when you want to delete file use this:
    FTPClass.Delete("ftp://yourUrl.com/public_html/filename.pdf");

Page 1 of 1 (3 items)