http://www.perlmonks.org?node_id=34202

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

I am trying to write a script that will upload a script from a PC via a web-browser. (The PC cant have FTP or perl) The script would be put onto a secure FTP server and then chmod'ed so that the script could be executed.

Originally posted as a Categorized Question.

  • Comment on how can i upload a file using a web-browser and the chmod() the file ?

Replies are listed 'Best First'.
Re: how can i upload a file using a web-browser and the chmod() the file ?
by merlyn (Sage) on Sep 27, 2000 at 19:22 UTC
    File uploading is fairly painless with CGI.pm. From the manpage:
    CREATING A FILE UPLOAD FIELD print $query->filefield(-name=>'uploaded_file', -default=>'starting value', -size=>50, -maxlength=>80); -or- print $query->filefield('uploaded_file','starting value',50 +,80); [...] When the form is processed, you can retrieve the entered filename by calling param(): $filename = $query->param('uploaded_file'); [...]
    You can then copy the file to the appropriate place (perhaps using the File::Copy core module), and then use the chmod operator to make it executable.

    An important security concern is to make sure your script is not available to the general populus, because you've effectively given an open prompt to whomever wants it.

Re: how can i upload a file using a web-browser and the chmod() the file ?
by AgentM (Curate) on Sep 28, 2000 at 00:26 UTC
    Minimally, you will want to turn on taint checking with -T. If you are uploading a picture, you'll want to check its "pictureness" with Image::Magick or some similar Module. In any case, you should set a maximum size for the file in the CGI Module using $CGI::POST_MAX and optionally scan the file to make sure that its corresponds with some given format. In the name of security, you should definitely take these extra steps to ensure the sanity of your filesystem.