Thread: Chmod using FTP

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    25
    Rep Power
    0

    Chmod using FTP


    Does anyone know of a way to use an FTP module to chmod file permissions on remote files?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    North Vancouver, BC, Canada
    Posts
    44
    Rep Power
    13

    Chmod in FTP example


    Try this basic idea :


    #!/path_to/perl

    use Net::FTP;

    .... after connecting and login ........

    $ftp->site("CHMOD 755 NEW.cgi") || die &error("Couldn't chmod NEW.cgi : $!");

    ........ other code .......
    $ftp->quit;
    exit;

    sub error {
    my ($msg) = shift;
    # if web based don't forget
    # print "Content-type: text/html\n\n";
    print $msg;
    $ftp->quit;
    exit();
    }



    Good Luck
    Foot in Mouth Ver 1.00
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    North Vancouver, BC, Canada
    Posts
    44
    Rep Power
    13

    Post Link for Net::Ftp module readme


    Here is a link on Net::FTP for syntax's


    http://www.cgi101.com/modules/Net.FTP.html


    thank's

    Foot in Mouth Ver 1.00

    Post example code, if you get stuck for ++Help;
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    North Vancouver, BC, Canada
    Posts
    44
    Rep Power
    13

    Post Ftp example with color comments


    #!/usr/bin/perl

    use Net::FTP;

    # Net::FTP part of libnet
    # http://www.cpan.org/authors/id/GBARR...-1.0703.tar.gz

    # set up some variables
    $host = "127.0.0.1"; # local host for this test script
    $username = "jen"; # Temp user Jenny
    $password = "jen"; # Her password
    $Folder = "/home/jen"; # Her home directory where she can write to

    # Connect
    $ftp = Net::FTP->new("$host") || die "Could not connect to $host : $!";
    # Login
    $ftp->login("$username","$password") || die "Could not login : $!";

    # Do some work -- assumes user can write to folder and use chmod
    $ftp->cwd("$Folder") || die "Could not cd to $Folder : $!";
    # assumes new.cgi right beside ftp.pl in same directory
    $ftp->put("new.cgi") || die "Could not put new.cgi : $!";
    $ftp->site("CHMOD 755 new.cgi") || die "Could not chmod new.cgi : $!";

    # Close Connection
    $ftp->quit;

    exit;

    # Tested on Red Hat Linux 7.0, perl 5.6, libnet-1.0703 and temp created user jen
    # Testing out color coding
    Thanks

    Foot in Mouth ver 1.2.5 Onion

IMN logo majestic logo threadwatch logo seochat tools logo