Go Premium for a chance to win a PS4. Enter to Win


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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

972 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