Problems deleteing PERL created files.

Posted on 1998-06-05
Medium Priority
Last Modified: 2010-03-04
    I've written a PERL script that creates a file.  The problem is when I log onto my ISP through CuteFTP and try to delete this file it tells me it's forbidden.  I'm guessing the premissions are incorrect, however I wish to leave the file at 755.  I'm guessing also that it's because PERL is creating the file and not me so I don't own the file.  So how would I go about bestowing ownership of this file upon myself.
Question by:cide
  • 2
  • 2

Accepted Solution

tpryor earned 100 total points
ID: 1207658
Your assumptions are correct.

To change ownership in perl you would use the "chown" keyword ie:
chown $uid, $gid, $filename;

heres a subroutine that looks everything up for you then does the chown.

sub chown_by_name {
      local ($user, $pattern) = @_;
      chown((getpwnam($user)) [2, 3], glob($pattern));

&chown_by_name("fred", "*.c");

notice that this forces the group of each file to be the gid fetched from the passwd file.  An alternative is to pass a -1 for the gid, which leaves the group of the file unchanged.

on most systems you are not allowed to change ownership of a file unless you are the superuser, although you should be able to shange the group to any of your secondary groups.

I would suggest building a file management app in perl this way you could use perl to delete and update the permissions associated with the files created by perl via the web.  you could also password protect this app so only you could access this app.


Author Comment

ID: 1207659
So if I replaced fred with my user name it should have worked if I had access to chown right? Cause it didn't.

Expert Comment

ID: 1207660
Thats correct.
If you make a simple perl/web interface to manage the files that perl creates for you would be your best bet.  I actually set the permissions to rwrwrw, and password protect the directory my perl created files live in then i just log in through ftp and im all set.
BTW, I dont think your host provider will give you superuser priv's.



Author Comment

ID: 1207661
I doubt that either! :P

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
Six Sigma Control Plans

589 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