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

I get 550 Permission denied error in the $ftp->put command in the code below. The directory to which I am placing my file has permissions 777, and there is no file with the same name, that would prevent writing. I would greatly appreciate any ideas or suggestion on what may be wrong.

#!/usr/bin/perl -w use strict; use warnings; require Net::FTP; my $ftp= Net::FTP->new("client-onboard1", Debug => 1) or die "Cannot c +onnect to client-onboard1\n"; $ftp->login("mylogin",'mypass') or die "Cannot login to client-onboard +1\n"; $ftp->cwd("/tmp/fcp/") or die "Cannot change working directory ", $ft +p->message; $ftp->get("test_rem") or die ("Could not upload\n"); #this line works $ftp->put("/mypath/test_fl") or die ("Could not upload\n"); #this fail +s with the permissions denied error.

Replies are listed 'Best First'.
Re: Help with NET::FTP
by runrig (Abbot) on Apr 29, 2011 at 14:49 UTC
    Have you tried to do the same thing with the command line ftp? As the same user that this script runs as? Could the error be a permissions issue on the source file/directory?
      This seems to be a permission issue -- and I am getting the same behavior from the command line ftp program. When I try to put files, even to my home directory, even when 'chmod 0777 .' I get permission denied. I even tried with a windows client. Same thing.

      Is it possible the ftp server is configured to prevent uploads? I've tried 'passive off' and 'epsv4' as well.

      I can use command-line sftp to upload, but have not been able to login via Net::SFTP.
Re: Help with Net::FTP
by Tux (Canon) on Apr 29, 2011 at 14:54 UTC

    And does explicitely specifying the target help?

    $ftp->put ("/mypath/test_fl", "test_fl") ...

    I know the docs state «If "REMOTE_FILE" is not specified then the file will be stored in the current directory with the same leafname as "LOCAL_FILE"», but I've seen stranger things happen in FTP world.


    Enjoy, Have FUN! H.Merijn
      I had a very similar error. For me it was because the environment variable FTP_PASSIVE was not set to 1, causing it to not connect passively.

      I could see the errors better when I connected via
       my $ftp= Net::FTP->new("server", Debug => 1)
      and in the debug I saw

      Net::FTP=GLOB(0x86cb364)>>> PORT 192,168,201,177,249,218
      Net::FTP=GLOB(0x86cb364)<<< 200 PORT command successful. Consider using PASV.
      Net::FTP=GLOB(0x86cb364)>>> ALLO 22246
      Net::FTP=GLOB(0x86cb364)<<< 550 Permission denied.
Re: Help with NET::FTP
by mr_mischief (Monsignor) on Apr 29, 2011 at 18:52 UTC

    I know this sounds backward, but have you tried it with more restrictive permissions? Some systems are configured to prevent you from doing anything remotely with world-writable permissions (other than changing those permissions) for security purposes. You really only need the user to be able to write if the FTP server has forked off to run as the user, which it should.

Re: Help with NET::FTP
by Eliya (Vicar) on Apr 29, 2011 at 14:27 UTC

    Maybe you want mypath/test_fl to be relative to the directory you changed into before (/tmp/fcp/)?   Just a guess, though.

    update: nonsense — misread source as destination...