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

Hi, I'm enjoying creating my own XHTML FTP app using NET::ftp on the server..

So far I can rename, delete and upload fine, but the trivial task of creating a new directory isn't behaving as I'd expect.

my $i2 = "/httpdocs/this_folder"; my $i3 = "new_folder"; $ftp->cwd($i2) or die "change to directory $i2: ".$ftp->message." - ". +$ftp->code; $ftp->mkdir($i3) or die "make new directory $i3: $ftp->message." - ".$ +ftp->code;
This does create the directory /httpdocs/this_folder/new_folder, as it should, but then dies returning

"make new directory : Invalid number of arguments. - 501 at /usr/lib/perl5/5.8.8/CGI/Carp.pm line 314"
instead of the new directory name..

Anyone got any ideas?

Thanks in advance,
rjc

Replies are listed 'Best First'.
Re: NET::ftp mkdir succeeds but then dies with 501?
by Anonymous Monk on May 07, 2009 at 22:39 UTC
    Do you mean Net::FTP(module names are case sensitive)? Try increasing Debug level so you can see more. Maybe its permissions, does it work from regular FTP client?
      Hi
      Yes, the NET::FTP module

      mkdir works from regular FTP and the permissions are standard - it's another one of our own servers
      The current settings producing that error message are Debug => 3,Passive => 1

      rjc
Re: NET::ftp mkdir succeeds but then dies with 501?
by philipbailey (Curate) on May 08, 2009 at 08:33 UTC
    (Reply removed)
      Just to update - I had to revisit this block of code recently with slightly more experience. Wrapping the code in an eval and viewing the resulting $@ revealed that the mkdir was in fact firing twice in immediate succession, producing the 501 error on the second attempt.
      $ftp->cwd($i2) or die "change directory $i2: ".$ftp->message." / ".$ft +p->code; my @nfiles = $ftp->dir; if(grep {$_ eq $i3} @nfiles){ die "make $i3: already exists"; } else { $ftp->mkdir($i3) or die "make directory ".$ftp->code; }
      Although still not obvious to me exactly where, it looks like code elsewhere was looping over the mkdir without being caught, so I rewrote, removing the eval/dies, which seems to behave as expected.
      push @errs,"cannot change directory from $ftp->pwd to i2: $ftp->messag +e" unless $ftp->cwd($i2); my @nfiles = $ftp->dir; push @errs,"cannot list directory $ftp->pwd: $ftp->message" unless @nf +iles; push @errs,"directory $n2 already exists in $ftp->pwd: $ftp->message" +if grep {$_ eq $n2} @nfiles; push @errs,"cannot make directory $n2 in $ftp->pwd: $ftp->message $ftp +->code" unless $ftp->mkdir($n2); $ftp->quit; if(@errs){ print join "<br />",@errs; }