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

Hi, I am working on a CGI script. Ideally, this CGI script (which resides on a sun server) could open all the files under a specified directory on the client PC. Is this possible? The web browser only lets you select individual files as input to the CGI script, so I guess it would be some sort of special "submit" method, or a command to read the client's machine.
  • Comment on opening files on a pc from unix server?

Replies are listed 'Best First'.
Re: opening files on a pc from unix server?
by Yohimbe (Pilgrim) on Feb 09, 2001 at 07:39 UTC
    Aha. Sounds like you want to implement uploading to a server. CGI.pm has an already well tested upload capability.
    This is the form creation
    #!/usr/bin/perl use CGI; my $query= new CGI; print $query->header; print $query->startform(-enctype => &CGI::MULTIPART); print $query->filefield(-name => 'uploaded_file', -default => "C:\Uploads\", -size => 50, -maxlength=> 80); print $query->endform;
    You'll also need to process the file upload, and thats documented in CGI.pm as well.
    #!/usr/bin/perl use CGI; my $query= new CGI; print $query->header; my $file=$query->param('uploaded_file'); while(<$file>) { print $_; # the contents of the upload file }

    --
    Jay "Yohimbe" Thorne, alpha geek for UserFriendly
Re: opening files on a pc from unix server?
by tadman (Prior) on Feb 09, 2001 at 07:43 UTC
    You really can't upload an entire directory using the standard HTML form tools. They only permit a single file to be sent, as you have observed. There are alternatives, though:
    • Ask that the user ZIP the files together first, and your CGI can un-ZIP this archive on the other end. This way you can send as many files as you want in one go, plus they're compressed to speed up transfers.
    • Write a Java application which asks for permission to read files from disk, so that it can forward them to your CGI application using HTTP, but the transfer is done by the Java application and not by the browser.
    Netscape and Internet Explorer, for example, are not designed to allow this kind of access to the user's computer. JavaScript can be dangerous enough, and it's pretty crippled with the level of access it has to your computer.

    There was an "attack" you could do with an auto-submitting form that had a file-upload select which had a value set to something like your Netscape 'preferences.js' file, such as "C:\Program Files\Netscape\Users\default\preferences.js", so they could presumably steal passwords and what have you. It depended on you having your files in the default installation directory.
Re: opening files on a pc from unix server?
by IndyZ (Friar) on Feb 09, 2001 at 07:03 UTC
    Well, your question is a little unclear, but there are several options. If by PC you mean Windows, you can use Samba (which compiles on Sun platforms AFAIK). If you mean a Unix variant, I would recommend NFS. Both of these solutions would allow you to access files as if they existed on your own system (they will appear in your local filesystem).

    Once again, if you really want us to help you, you will need to be more specific. And you should get a username. People have a tendency to take you more seriously then.

    --
    Brian