Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Downloading multiple files

by Anonymous Monk
on Jun 16, 2000 at 17:02 UTC ( [id://18452]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi!! I have an web application wherein the user must have the facility to select multiple files that reside on the server file system and download all of them at one go. How can I do this?

Replies are listed 'Best First'.
Re: Downloading multiple files
by Corion (Patriarch) on Jun 16, 2000 at 17:08 UTC

    There is no such way to download multiple files in one go. with http. I see two possibilities. Either you use the tar program (or the Archive::Tar module) to pack all files together into one file to download, or you create a page which opens the download URLs for all files via JavaScript in pop-up fashion.

    The second method has many pitfalls of browser compatibility, client bandwidth and client stupidity, you also have to make sure that each client can also manually download all files. I would recommend looking into the one-file-solution.

      Corion said:
      ... Either you use the tar program (or the Archive::Tar module) to pack all files together into one file to download ...
      I just did a WT column that creates a small "shopping cart" and builds a .tar.gz file on the fly, even renaming it some nice unique name. If it's not online yet, it'll be there within a month, since it's one of the recent columns.

      -- Randal L. Schwartz, Perl hacker

Re: Downloading multiple files
by Zoogie (Curate) on Jun 16, 2000 at 18:21 UTC
    I think that Corion has the right idea with tar'ing the files together. A simple way to do it without modules or temporary files is to use backticks:
    print(`tar cf - $file1 $file2 $file3`);
    More info on doing this can be found at a question I asked earlier: Auto-Backup Questions

    - Zoogie

      Or use the Archive::TAR module. Saves you the overhead of launching a tar process.
Re: Downloading multiple files
by lhoward (Vicar) on Jun 16, 2000 at 17:42 UTC
    What I am about to suggest makes me feel dirty even thinking about it.... I'm not even sure if it would work, but.....

    How about using a frameset with a bunch of invisible (1 pixel) frames each of which triggers the download for one of the files that needs to be sent?

(jcwren) RE: Downloading multiple files
by jcwren (Prior) on Jun 16, 2000 at 17:34 UTC
    I've only written apps that download single files, so I have no experience with what AM is trying to do. I agree that you're correct about requiring a manual method.

    Now, assuming he was using Netscape, could you not do a multipart-form/server push to do what he's trying to do? (IE doesn't support multipart-form, if you've never tried. That caused me a few hours of grief).

    --Chris
RE: Downloading multiple files
by gregorovius (Friar) on Jun 16, 2000 at 21:08 UTC
    Tarring the files would probably not be an option for this AM. It assumes that clients will be able to untar the files, which is not something you can assume for an open- to-the-public site.

    I think he could investigate if there's a way to do it with java applets, though he may encounter trouble in piercing through the browser sandbox to save files to disk.
Re: Downloading multiple files
by AgentM (Curate) on Jun 16, 2000 at 18:26 UTC
    I have a better solution. If you want the illusion that you're downloading multiple files at the same time, you can use Perl Threads. In its simplest form, you could use...
    use Threads;
    async{
     download($file1); #function that grabs the file
    }
    async{
      download($file2);
    }#etc
    But be careful with threads. You only get the illusion that you are working concurrently (that is, assuming a single processor, single net connection). The concurrent downloads may or may not speed up the process (if you interested in that sort of thing). If you think my answer has nothing to do with your question, than ignore it and try to write a more descriptive question the next time around.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://18452]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found