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

Dear Monks,

Iam try to copy few files from my linux machine to another linux machine using Net::FTP

#!/usr/bin/perl use Net::FTP; $ftpobj = Net::FTP -> new ("station1")or die "Cannot connect to statio +n1:"; print "Sending files to station1\n"; $ftpobj -> login("stat1","stat1pass") or die "login failed ", $ftpobj- +>message; $ftpobj -> cwd ("/usr/local/bin") or die "cwd failed ", $ftpobj->messa +ge; $ftpobj -> put ("/home/raj/myc/fm/backup/inside.pl") or die "put faile +d ", $ftpobj->message;
when iam try to ftp the files to other folder, iam able to copy, but I can't copy to stat1's "/usr/local/bin" folder. It prompts put failed inside.pl: Permission denied. I know the superuser password, but don't know how to pass or change to superuser mode after getting connected. Please help me how to ftp to those folders which can be accessed only by the superuser.

Replies are listed 'Best First'.
Re: FTP script
by davido (Cardinal) on Jan 13, 2005 at 05:50 UTC

    Are you sure your login was successful? You're not checking for login success. You're also not checking for cwd() success. So the fact is that the preceeding script could have failed at login(), or at cwd(), and you wouldn't know, because you're not checking their success.

    Your 'or die...' check on put() is also pretty unhelpful, because it's not telling you the important information held in $ftpobj->message().

    This is all covered in synopsis of the POD for Net::FTP. Always read a module's POD before using it. ;) ....it's like reading the instructions before attempting to put together ready-to-assemble furniture.


    Dave

Re: FTP script
by jfroebe (Parson) on Jan 13, 2005 at 07:10 UTC

    hi,

    Most systems have (atleast should!) their superuser accounts locked down. From what I gather from your posting, is that you are looking for the ability to switch users (su/sudo) to the root user. This is not possible as there is no provision for this with ftp.

    What I would suggest, is to place the files in a holding area and then a cron job moves the files to the correct location. Personally I would opt for use of scp for security reasons.

    Jason L. Froebe

    Team Sybase member

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: FTP script
by svenXY (Deacon) on Jan 13, 2005 at 09:18 UTC
    Hi texuser74,

    I suggest to do this with File::Remote instead. It supports ssh/scp and you can then copy over existing files.

    Some code:
    use File::Remote; my $remote = new File::Remote(rsh => "/usr/bin/ssh", rcp => "/usr/bin/scp" ); $remote->copy("/local/file", "host:/remote/file") or warn $!;
    This should get you go, I hope.

    Sven