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

Gandalf,

I have a script which successfully logs in to an ftp server and perform the cwd() command.

However, when I perform the put() command, I get an "Access is denied" error.

I don't know why, since I make it by the login command o.k.

Here is the code, any help is greatly appreciated:

use Net::FTP qw(); sub main { $ftp=Net::FTP->new("ebizftp.honda.com",Timeout=>240) or $newerr=1; die "Can't ftp to ftp://ftpsite.blah.com : $! " if $newerr; $ftp->login('username', 'password') or die "Cannot login. ", $ftp->mes +sage; $ftp->cwd("\/genex\/AcuraWeb\/Transfer") or $newerr=1; die "Can't cd: $ftp->message \n" if $newerr; # it makes it to here o.k., and then dies on this following "put" comm +and, with the "Access is denied" command $ftp->put("filename.txt") or die "Couldn't put the file ", $ftp->messa +ge; $ftp->quit;

20070821 Janitored by Corion: Added code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: "Access denied" error received even _after_ logging in.
by Popcorn Dave (Abbot) on Aug 18, 2007 at 01:13 UTC
    Have you tried doing manually what your script does to verify that what you're trying to do works at all? That may give you a clue as to what is failing.


    Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

    I would love to change the world, but they won't give me the source code

Re: "Access denied" error received even _after_ logging in.
by jZed (Prior) on Aug 17, 2007 at 22:59 UTC
    What is the access permission on the directory? Does the user you are logged in as have permissions to write to that directory?
      Hi, I just checked and I am allowed write access to the folder. Any other ideas? I would be happy to try anything. Brent.
Re: "Access denied" error received even _after_ logging in.
by Aim9b (Monk) on Aug 18, 2007 at 01:04 UTC
    Perhaps the file already exists & can't be overwritten (readonly)?
Re: "Access denied" error received even _after_ logging in.
by roboticus (Chancellor) on Aug 18, 2007 at 11:12 UTC
    Try listing the current directory before the put. Perhaps your cwd command isn't putting you where you think it is. I've seen (and use daily!) an ftp server that lets you cwd to anywhere you like without giving you an error. Until you actually try to do something, in which case you get the "Access is denied" message.

    OBTW: why are you escaping forward slashes?

    ...roboticus

Re: "Access denied" error received even _after_ logging in.
by dwm042 (Priest) on Aug 18, 2007 at 13:15 UTC
    I manage a corporate FTP site whose outbound code is using Net::FTP and roboticus is dead on. Net::FTP doesn't lie. If it says access denied there is an access error. In other words, you don't have permission to put the file where you are trying to put it. So, check where you are when you try 'put'. Have your code fetch and print the remote directory you are in. Also, doing the transfer manually will also give you some insight into how your transfer is failing.

Re: "Access denied" error received even _after_ logging in.
by bruceb3 (Pilgrim) on Aug 18, 2007 at 22:08 UTC
    Please consider that you may not have permission to _read_ the file locally. It's just another thing to check.
      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.