Permissions on a file

Discussion in 'Perl Misc' started by kronecker@yahoo.co.uk, May 16, 2008.

  1. Guest

    I create a text file on the server remote.txt ok with the following
    code (the last part of it)


    $first_name = $FORM{command1};
    $last_name = $FORM{command2};

    open (example, ">remote.txt") || die ("Could not open file. $!");

    print example "$first_name\n$last_name\n";

    close (example);

    print "Content-type:text/html\r\n\r\n";
    This bit causes errors...... chmod
    0777,'remote.txt'; ......................................
    print "<html>";
    print "<head>";
    print "<title> Processed</title>";
    print "</head>";
    print "<body>";
    print "<h2>Commands $first_name $last_name - Sent to text file</h2>";
    print "</body>";
    print "</html>";


    The problem is that I need to be able to delete this file remotely
    using FTP and the script generate a new version every now and then. I
    need teh script to make the file deleteable. How do I do this?
    I tried chmod 0777,'remote.txt' and it spews out errors.


    K.
    , May 16, 2008
    #1
    1. Advertising

  2. wrote in news:27a86a81-91bd-4d5c-87ff-
    :

    > I create a text file on the server remote.txt ok with the following
    > code (the last part of it)


    You should always, yes always,

    use strict;
    use warnings;

    > $first_name = $FORM{command1};
    > $last_name = $FORM{command2};
    >
    > open (example, ">remote.txt") || die ("Could not open file. $!");


    We have been through this once before

    my $filename = 'remote.txt';

    open my $EXAMPLE, '>', $filename
    or die "Cannot open '$filename': $!";

    > print example "$first_name\n$last_name\n";


    print $EXAMPLE "$first_name\n$last_name\n";

    > close (example);


    It is crucial to check for errors on close on a filehandle opened for
    writing.

    close $EXAMPLE or die "Error closing '$filename': $!";

    > print "Content-type:text/html\r\n\r\n";
    > This bit causes errors...... chmod
    > 0777,'remote.txt'; ......................................


    What errors does it cause?

    chmod 0777, $filename
    or die "Cannot chmod on '$filename': $!";

    Have you read perldoc -f chmod and perldoc -f umask?

    > print "<html>";
    > print "<head>";
    > print "<title> Processed</title>";
    > print "</head>";
    > print "<body>";
    > print "<h2>Commands $first_name $last_name - Sent to text file</h2>";
    > print "</body>";
    > print "</html>";


    Don't be silly!

    print <<EO_HTML;
    <html>
    <head>
    <title>Processed<title>
    </head>
    <body>
    <h2>Commands $first_name $last_name - Sent to text file</h2>
    </body>
    </html>
    EO_HTML

    > The problem is that I need to be able to delete this file remotely
    > using FTP and the script generate a new version every now and then. I
    > need teh script to make the file deleteable. How do I do this?
    > I tried chmod 0777,'remote.txt' and it spews out errors.


    Did you try looking at the error messages?

    Sinan


    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://www.rehabitation.com/clpmisc/
    A. Sinan Unur, May 16, 2008
    #2
    1. Advertising

  3. Bill H Guest


    > The problem is that I need to be able to delete this file remotely
    > using FTP and the script generate a new version every now and then. I
    > need teh script to make the file deleteable. How do I do this?
    > I tried chmod 0777,'remote.txt' and it spews out errors.
    >
    > K.


    I believe your problem is not a perl issue but a permission issue. The
    script is running under a webmaster or other account and the file
    created is owned by that creator, yet your ftp access is under a
    different account name. If you have shell access, do a ls -l on that
    directory to see who is the owner / group, that is who you need to be
    to delete it. If you have ftp access as the server admin (versus the
    webmaster) you can delete the file then (at least this has been my
    experience).

    I run into this all the time when a client gives me ftp access to
    their website and gives me a webmaster account and wants me to update
    their stuff that they posted using a different account. Interesting
    thing I have seen is that I can most of the time rename what they have
    then post my changed files, but can't delete what they have (or
    overwrite it).

    Back on the perl issue, I did find away around this about 7 / 8 years
    ago by using chown on the file after creating it to change who owned
    the file from within a perl script.

    Bill H
    Bill H, May 16, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark

    File upload permissions

    Mark, Nov 12, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    548
    Suresh
    Nov 12, 2003
  2. Scott Allen
    Replies:
    0
    Views:
    433
    Scott Allen
    Jul 13, 2004
  3. Curt K
    Replies:
    0
    Views:
    562
    Curt K
    Nov 3, 2006
  4. N. Quisitive
    Replies:
    0
    Views:
    131
    N. Quisitive
    Jan 17, 2006
  5. Vikram Sharma
    Replies:
    2
    Views:
    158
    Vikram Sharma
    Dec 1, 2008
Loading...

Share This Page