Solved

uploading and downloading files

Posted on 2000-02-21
5
181 Views
Last Modified: 2010-03-05
how do i upload and down load files using perl( in a Web application) giving the user the option to choose file(s) from a directory(location)...????
0
Comment
Question by:babykai
5 Comments
 

Expert Comment

by:KishoreS78
Comment Utility
see Net::FTP module
u could play around with ftp transferring files.
0
 
LVL 1

Expert Comment

by:dmag
Comment Utility
Please explain what you want in more detail. Is this a web application? Do you want to use FTP? or what?
0
 
LVL 3

Expert Comment

by:alien_life_form
Comment Utility
Greetings.

If this is a web application:

i) for downloading, you need nothing more than a link to the appropriate file.

ii) For uploading, you can use CGI.pm, taking advantage of its multipart form support- it will do exactly what you want, from within a browser. CGI.pm's documentation is bundled with perl.

Cheers,
   alf
0
 

Author Comment

by:babykai
Comment Utility
Edited text of question.
0
 

Accepted Solution

by:
baralong earned 10 total points
Comment Utility
To upload the file you need something like:

<form enctype="multipart/form-data" action="http://server/accept.pl" method="post">
<input name="my_file" type="file">
</form>

Most browsers implement the the input type="file" tag with a button the brings up a file selector window.

In accept.pl have something like:

use CGI;
$query= new CGI;
$fileup = $query->param('my_file');

# extract its name
$strFilename = $fileup;
$strFilename =~ s/.*\\([^\s\\]+)$/$1/;

# build a name for the file on the server
$localFile =~ s/\\[^\s\\]+$//;
$localFile .= "\path\" . $strFilename;
 
# save the file
open (OUTFILE,">$localFile");
binmode($fileup);
binmode(OUTFILE);
while ($bytesread=read($fileup,$buffer,1024)) {
      print OUTFILE $buffer;
}

You will only need the binmode statements if the OS you are using diferentiates between text and binary files (eg windows, or at least the version that I'm using)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
OTRS Installation 1 276
sort hash by values desc 2 174
Bash one liner, start and end time calculation 13 93
add a syntax to a csv file 8 91
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now