Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Downloading an entire directory

Status
Not open for further replies.

chrismassey

Programmer
Aug 24, 2007
264
GB
Hello,

I have written a script which lets me download individual files from my web server to a PC, however I want to be able to download entire diriectories rather than individual files. Here is the script to download an individual file...

Code:
#! /usr/bin/perl
use strict;
use CGI ':standard'; 
use CGI::Carp qw(fatalsToBrowser);

my $files_location;  
my $ID;  
my @fileholder;

$files_location = "/PATH/chrismassey.co.uk/Perl/Scripts/ControlPanelV1.0/";

$ID = "z/Properties/Images/Logo1.bmp";  

if ($ID eq '') {  
print "Content-type: text/html\n\n";  
print "You must specify a file to download.";  
} else {

open(DLFILE, "<$files_location/$ID") || Error('open', 'file');  
@fileholder = <DLFILE>;  
close (DLFILE) || Error ('close', 'file');

print "Content-Type:application/x-download\n";  
print "Content-Disposition:attachment;filename=$ID\n\n"; 
print @fileholder 
### end else
}

sub Error { 
       print "Content-type: text/html\n\n"; 
   print "The server can't $_[0] the $_[1]: $! \n"; 
   exit; 
 }

Thanks
 
What is the program you are developing going to be for?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
The program allows a client to backup an entire directory to his computer. This is so that he can have a hard copy of the files. I was thinking that I could process all files in a directory recursively, however I don't want a save dialog box to pop up for every file that is being saved.

Chris
 
Why not use FTP for the backup if it's going to be an entire directory? Probably want to zip the files too.

I'm sure you could make a recursive function but I think FTP is the way to go here.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thank you Kevin,

I have looked into FTP access and also zipping files...

It should work

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top