Getting list of files in directory from a web site

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Opa

    Getting list of files in directory from a web site

    Hi,

    Does anyone know how to get a list of files for a given directory from a
    given url.
    I have the following, but get an error indicating that URI formats are not
    supported.

    System.IO.Direc toryInfo di
    di = new System.IO.Direc toryInfo("http://www.websitehere .com/files/");
    System.IO.FileI nfo[] rgFiles = di.GetFiles("*. jpg");
    foreach(System. IO.FileInfo fi in rgFiles)
    {
    MessageBox.Show (fi.Name);
    }

    Is there a way of doing this without ftp?

  • John Timney \(Microsoft MVP\)

    #2
    Re: Getting list of files in directory from a web site

    The web site must allow directoy browsing, and the result you get back from
    requesting a dir with no default directoy could be parsed. If it has a
    default page set you cant list the dir contents. This is how web servers
    work by design.

    --
    Regards

    John Timney
    Microsoft Regional Director
    Microsoft MVP

    "Opa" <Opa@discussion s.microsoft.com > wrote in message
    news:B32BE48C-28E8-4807-B79C-5609F419F20E@mi crosoft.com...[color=blue]
    > Hi,
    >
    > Does anyone know how to get a list of files for a given directory from a
    > given url.
    > I have the following, but get an error indicating that URI formats are not
    > supported.
    >
    > System.IO.Direc toryInfo di
    > di = new System.IO.Direc toryInfo("http://www.websitehere .com/files/");
    > System.IO.FileI nfo[] rgFiles = di.GetFiles("*. jpg");
    > foreach(System. IO.FileInfo fi in rgFiles)
    > {
    > MessageBox.Show (fi.Name);
    > }
    >
    > Is there a way of doing this without ftp?
    >[/color]


    Comment

    • Cor Ligthert

      #3
      Re: Getting list of files in directory from a web site

      Opa,

      No what you ask is typical FTP and than the directory has to be on a FTP
      server (and be configured there as an ftp directory).

      For HTTP this should normally absolute be impossible and therefore made
      every day more impossible.

      I hope this helps a little bit.

      Cor


      Comment

      • Nick Malik

        #4
        Re: Getting list of files in directory from a web site

        Hi Cor,
        [color=blue]
        > For HTTP this should normally absolute be impossible and therefore made
        > every day more impossible.[/color]

        If directory browsing is turned on for the site, then this works just fine.
        If you look at the RFC for HTTP 1.1, you will see that directory browsing is
        a normal and supported use of HTTP. In fact, it was the original use.
        Default pages were a later invention.



        By the way, there is nothing wrong with doing this if all your pages are
        simple text or HTML. There are many tens of thousands of older web sites
        that still operate this way. This is not a security risk if the site
        contains only text (and some still do).

        --- Nick


        Comment

        • Cor Ligthert

          #5
          Re: Getting list of files in directory from a web site

          Hi Nick,

          Can you show me a sample how to do that getting a "List of files in a
          directory from a website" with HTTP 1.1

          I am as well very interested in that

          Cor
          [color=blue]
          >[color=green]
          > > For HTTP this should normally absolute be impossible and therefore made
          > > every day more impossible.[/color]
          >
          > If directory browsing is turned on for the site, then this works just[/color]
          fine.[color=blue]
          > If you look at the RFC for HTTP 1.1, you will see that directory browsing[/color]
          is[color=blue]
          > a normal and supported use of HTTP. In fact, it was the original use.
          > Default pages were a later invention.
          >
          > http://www.w3.org/Protocols/rfc2068/rfc2068
          >
          > By the way, there is nothing wrong with doing this if all your pages are
          > simple text or HTML. There are many tens of thousands of older web sites
          > that still operate this way. This is not a security risk if the site
          > contains only text (and some still do).
          >
          > --- Nick
          >
          >[/color]


          Comment

          • Nick Malik

            #6
            Re: Getting list of files in directory from a web site

            Sure Cor,

            1) open any web site on your web server or create a new one. put a text or
            simple HTML file in it. I called mine "mynewsite"
            2) open the properties for that site in IIS manager. Check "allow directory
            browsing". click OK
            3) using IE, hit your site, but don't specify any file name.


            you will get a list of the files in the site with a link under each
            filename. click the link to open the page.

            I'm on Windows 2000 here (I'm at home... I have XP and WS2003 at work). I
            set this up in about 2 minutes.

            --- Nick

            "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
            news:uxC3kMAkEH A.1656@TK2MSFTN GP09.phx.gbl...[color=blue]
            > Hi Nick,
            >
            > Can you show me a sample how to do that getting a "List of files in a
            > directory from a website" with HTTP 1.1
            >
            > I am as well very interested in that
            >
            > Cor
            >[color=green]
            > >[color=darkred]
            > > > For HTTP this should normally absolute be impossible and therefore[/color][/color][/color]
            made[color=blue][color=green][color=darkred]
            > > > every day more impossible.[/color]
            > >
            > > If directory browsing is turned on for the site, then this works just[/color]
            > fine.[color=green]
            > > If you look at the RFC for HTTP 1.1, you will see that directory[/color][/color]
            browsing[color=blue]
            > is[color=green]
            > > a normal and supported use of HTTP. In fact, it was the original use.
            > > Default pages were a later invention.
            > >
            > > http://www.w3.org/Protocols/rfc2068/rfc2068
            > >
            > > By the way, there is nothing wrong with doing this if all your pages are
            > > simple text or HTML. There are many tens of thousands of older web[/color][/color]
            sites[color=blue][color=green]
            > > that still operate this way. This is not a security risk if the site
            > > contains only text (and some still do).
            > >
            > > --- Nick
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Nick Malik

              #7
              Re: Getting list of files in directory from a web site

              Did anyone ever answer your question?

              Use HTTPWebClient. I don't know if you can use the URI of .../files/*.jpg
              or if you have to just say .../files/* and then look for the JPG files.

              Note: this will only work if the web server has directory browsing turned on
              for this site.

              I don't know if you get the same HTTP response with different web servers.
              I would suspect that you do, but I haven't dug far enough into the W3C RFCs
              to see if there's a standard for returning the file list.

              --- Nick

              "Opa" <Opa@discussion s.microsoft.com > wrote in message
              news:B32BE48C-28E8-4807-B79C-5609F419F20E@mi crosoft.com...[color=blue]
              > Hi,
              >
              > Does anyone know how to get a list of files for a given directory from a
              > given url.
              > I have the following, but get an error indicating that URI formats are not
              > supported.
              >
              > System.IO.Direc toryInfo di
              > di = new System.IO.Direc toryInfo("http://www.websitehere .com/files/");
              > System.IO.FileI nfo[] rgFiles = di.GetFiles("*. jpg");
              > foreach(System. IO.FileInfo fi in rgFiles)
              > {
              > MessageBox.Show (fi.Name);
              > }
              >
              > Is there a way of doing this without ftp?
              >[/color]


              Comment

              • Cor Ligthert

                #8
                Re: Getting list of files in directory from a web site

                Nick,

                I did not know this, however doing it I saw there should as well not be a
                default page in that folder.

                (Just for the thread)

                Thanks,

                Cor
                [color=blue]
                > 1) open any web site on your web server or create a new one. put a text[/color]
                or[color=blue]
                > simple HTML file in it. I called mine "mynewsite"
                > 2) open the properties for that site in IIS manager. Check "allow[/color]
                directory[color=blue]
                > browsing". click OK
                > 3) using IE, hit your site, but don't specify any file name.
                > http://localhost/mynewsite
                >
                > you will get a list of the files in the site with a link under each
                > filename. click the link to open the page.
                >
                > I'm on Windows 2000 here (I'm at home... I have XP and WS2003 at work). I
                > set this up in about 2 minutes.[/color]


                Comment

                • Devdex Developer

                  #9
                  Re: Getting list of files in directory from a web site



                  May b error is coming because IIS is not configured to be for *.jpg.

                  please read the following article.


                  *** Sent via Developersdex http://www.developersdex.com ***
                  Don't just participate in USENET...get rewarded for it!

                  Comment

                  Working...