Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

chmod of an FTP transfer via perl

by blue_cowdawg (Monsignor)
on Aug 18, 2003 at 14:15 UTC ( [id://284588]=perlquestion: print w/replies, xml ) Need Help??

blue_cowdawg has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks,

I am about to write a utility script to automate the uploading of files to a remote server in Perl. An old trick of mine that I'd love to use is to change the permission bits on the transferred file once it has finished transfer so that a daemon that watches the upload directory knows that the transfer is complete.

I looked at the man page for Net::FTP and do not see a method for chmod. Has anybody out there accomplished a chmod from Perl across an FTP connection?


Peter @ Berghold . Net

Sieze the cow! Bite the day!

Nobody expects the Perl inquisition!

Test the code? We don't need to test no stinkin' code!
All code posted here is as is where is unless otherwise stated.

Brewer of Belgian style Ales

Replies are listed 'Best First'.
Re: chmod of an FTP transfer via perl
by Elian (Parson) on Aug 18, 2003 at 14:25 UTC
    You need to use the FTP SITE method for this. FTP is an old, old protocol (one of the first--the original RFCs date back to the early '70s) and it has no inherent support for, amongst other things, file permissions. So to set the permissions you need to execute a command on the remote server, via SITE, to do this.

    You may find you can't, as the site interface is often either restricted or completely locked down, but if you're lucky it'll be there. Unfortunately because the site interface is being used you can't count on any sort of consistency across servers, but if you're using wu-ftpd or something compatible, the command looks like:

    $ftp->site("CHMOD $mode $file");
    If you're not lucky, well, check your server docs and hope for the best.
Re: chmod of an FTP transfer via perl
by cbro (Pilgrim) on Aug 18, 2003 at 14:29 UTC
    I found this here
    .... after connecting and login ........ $ftp->site("CHMOD 755 NEW.cgi") || die &error("Couldn't chmod NEW.cgi +: $!"); ........ other code .......

    BTW, I marked this for deletion, but the other two duplicates were already deleted by the time I submitted the request.
    Sorry :)

    HTH,
    Chris

          BTW, I marked this for deletion, but the other two duplicates were already deleted by the time I submitted the request.
      'ts-ok.... I think I just learned about a ahem! feature of this site that I need to be careful of in the future.

      Feeling very sheepish....


      Peter @ Berghold . Net

      Sieze the cow! Bite the day!

      Nobody expects the Perl inquisition!

      Test the code? We don't need to test no stinkin' code!
      All code posted here is as is where is unless otherwise stated.

      Brewer of Belgian style Ales

        Yep. You generally can't edit top-level nodes, though you can normally edit reply nodes. One more reason to make sure things look right with that nice little preview button before sumitting. :)
Re: chmod of an FTP transfer via perl
by Mr. Muskrat (Canon) on Aug 18, 2003 at 14:28 UTC
    I haven't tried it yet but you should be able to use the quot method to perform a chmod.

      Tried quot, didn't work... tried SITE as suggested by Elian and it worked.


      Peter @ Berghold . Net

      Sieze the cow! Bite the day!

      Nobody expects the Perl inquisition!

      Test the code? We don't need to test no stinkin' code!
      All code posted here is as is where is unless otherwise stated.

      Brewer of Belgian style Ales

        Yep. I tested it a few minutes ago and confirmed that $ftp->quot('chmod', "$perms $file"); doesn't work as I thought it would. I'm glad to see that site does work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://284588]
Approved by Elian
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-24 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found