uploading and downloading files

Posted on 2000-02-21
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)...????
Question by:babykai

Expert Comment

ID: 2543550
see Net::FTP module
u could play around with ftp transferring files.

Expert Comment

ID: 2544898
Please explain what you want in more detail. Is this a web application? Do you want to use FTP? or what?

Expert Comment

ID: 2545209

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, taking advantage of its multipart form support- it will do exactly what you want, from within a browser.'s documentation is bundled with perl.


Author Comment

ID: 2545377
Edited text of question.

Accepted Solution

baralong earned 10 total points
ID: 2567929
To upload the file you need something like:

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

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

In 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");
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)

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl to mysql 5 129
perl script help 5 232
How to search multiple patterms in a file with perl? 4 79
Regex rule to match two different url 5 58
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

947 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

19 Experts available now in Live!

Get 1:1 Help Now