Solved

Open file to write

Posted on 1998-11-25
5
140 Views
Last Modified: 2010-03-04
I have the following script on one of my NT servers.  It is accessed from an html form.  It prints out the 1st and 3rd files, but it can't open the second one.  It works on other servers.  The server admin says he has all of the permissions set correctly.  Why not?

#!c:\perl\bin\perl.exe

$basdir = "d:\\websites\\botten\\cgi-bin\\";
$abc = $basdir . "test.txt";
$def = $basdir . "iden.txt";
print "Content-type: text/html\n\n";

open(NAM2, "$def") || print "a can't open<br>";
$input = <NAM2>;
print "$input<br>";
close NAM2;

open(NAM2, ">$abc") || print "b can't open<br>";
print NAM2 ("abcdefgh\n");
close NAM2;

open(NAM2, "$abc") || print "c can't open<br>";
$input = <NAM2>;
print "$input<br>";
close NAM2;
exit;
0
Comment
Question by:donb1
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:b2pi
ID: 1206623
Try changing your open lines to:

open(NAM2, ">$abc") || print "b can't open ($!)<br>";
print NAM2 ("abcdefgh\n");
close(NAM2);


On the other hand, if you were a web-site administrator, would _YOU_ give every user write access to the cgi-bin (and if so, how would you prevent someone evil from uploading a perl program to your cgi-bin, and using it to delete everything else?)
0
 

Author Comment

by:donb1
ID: 1206624
b2bi -
The script isn't the problem.  It works on 2 other NT servers.  The problem is in the NT settings at the server.  Also cgi-scripts aren't of much value if you can't write to a file.  How is someone going to upload a file to the server without a password??
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1206625
b2pi suggestion will at least tell you the reason, anyhow.

If you know that the permissions are the problem, could you please verify
If the user under which this cgi runs has change and create permissions in
both, the directory and the corresponding share.
0
 

Author Comment

by:donb1
ID: 1206626
Permissions are denied, so I will need to wait until after the ISP returns from the long week-end.  I would think that Microsoft would give some kind of support to ISPs running NT so that they would know how to set up permissions.
Thanks
0
 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1206627
The reason I simply didn't say that the permissinos didn't exist on that directory is because you explicitly stated that the permissions were set correctly.  In fact, I'd agree with him. You don't have to wait.  Create a directory someplace else, and allow write access to all.  Then, write to that directory.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 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