Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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

721 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