in reply to File::Copy across a Network

As you are running an Apache server and just want to upload files to it all you need to do is write a dozen line CGI script that uses CGI or even easier CGI::Simple to do the file upload. Something like:

#!/usr/bin/perl -w use strict; use CGI::Simple; $CGI::Simple::DISABLE_UPLOADS = 0; # enable uploads $CGI::Simple::POST_MAX = 1_048_576; # allow 1MB uploads my $q = new CGI::Simple; my $target = '/path/to/write/file.name'; $q->param('upload_file') ? upload() : request_file(); exit; sub upload { $q->upload( 'upload_file', $target ); } sub request_file { print $q->header; print <<HTML; <HTML> <BODY> <FORM METHOD="POST" ACTION="http://localhost/cgi-bin/script.cgi"; ENCTYPE="multipart/form-data"> <INPUT TYPE="file" NAME="upload_file" SIZE="42"> </FORM> </BODY> </HTML> HTML }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: File::Copy across a Network
by Anonymous Monk on May 03, 2002 at 16:23 UTC
    That's fantastic. Thanks v much. Unfortunately I don't know how to call this type of script from the rest of my Perl stuff. Can you give me any tips on this? It also seems to crash unless I unclude:

    print "Content-type:text/html\n\n";

      Sorry code was bare bones (as well as untested :-). With CGI you need a valid header which I neglected with the upload sub. To call it from perl use LWP which is a perl HTTP client (effectively a very basic browser). There are a ton of LWP examples on this site, use Super Search. To call it from any client machine just use a browser and browse to the script on the server.

      sub upload { if ($q->upload( 'upload_file', $target )) { print $q->header, "Uploaded ", $q->param('upload'), "OK\n"; } else { print $q->header, "Oops!\n"; } }

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print