On 10/22/21 16:20, ToddAndMargo via perl6-users wrote:
On 10/22/21 09:22, Brian Duggan wrote:
On Thursday, October 21, ToddAndMargo via perl6-users wrote:
Do we have a working ftp module yet?

There are a few modules that use libcurl, which supports FTP
e.g. https://raku.land/github:CurtTilmes/LibCurl

Brian



Hi Brian,

Thank you.

I really need access to the full set of FTP commands, especially when I am drilling down directories renaming
things that won't delete properly.

-T


This is what the more complicated stuff I am doing.
I call myself here and limit myself to how many
levels I will drill down.

By the way, the mass FTP recursive directory delete
won't work if it find some file names it does not
like, so I have to whack them one at a time.

-T

sub RmdirAndLoop ( $$$ );

sub RmdirAndLoop ( $$$ ) {

   my $Target      = $_[0];  # directory to clean out

   my $Depth       = $_[1];  # what level subdirectory you are on

   my $MaxDepth    = $_[2];  # Limit as to how far to dig down



my $DirTablePtr = GetDirHashPtr ( $Target ); # Array of Hashes 'Type" and 'Name'



if ( $Depth == 0 ) { print "Pruning <$Target>. This may take a while...\n"; }

   if ( $ftp->rmdir ( "$Target", 1 ) ) { return 1; }



   # clean up anything that got away

   for my $DelPtr ( @{ $DirTablePtr } ) {





      if ( $$DelPtr{'Type'} eq "File" ) {

                

                  my $FileName = "$Target/$$DelPtr{'Name'}";

                  # $FileName =~ s/\+/\\+/g;

                  # $FileName =~ s/\;/\\;/g;

                  # $FileName =~ s/\(/\\(/g;

                  # $FileName =~ s/\)/\\)/g;

                  # $FileName =~ s/\ /\\ /g;

                

                  $ftp->delete ( "$FileName" );

                  if ( Exists ( "$FileName", 0 ) ) {

                     print "File <$FileName> failed to delete\n";

                     # return 0;

                  } else {

                         # print "File <$FileName> was deleted\n";

             }



          } elsif ( $$DelPtr{'Type'} eq "Directory" ) {

                

         if ( $Depth > $MaxDepth ) {

            print "   MaxDepth of $MaxDepth Exceeded\n";

                      return 1; }

                

                   my $DirName = "$Target/$$DelPtr{'Name'}";

         # Note: you have to escape plus signs, may soem others

                

                

# Dive down into the directory and clean it out before trying to remove the directory

                   # print "Drilling down to $DirName\n";

                

                   my $ShortDirName = $DirName;

                   $ShortDirName =~ s{.*/}{};

                   print "  " x ${Depth} . "Drilling down to depth <",

                      ( $Depth + 1 ), ">\ <$ShortDirName>\n";



# when you come back, presume that the directoy to be deleted is not empty

         RmdirAndLoop ( "$DirName", ( $Depth + 1 ), $MaxDepth );



                

                   $DirName =~ s/\+/\\+/g;

                   # $DirName =~ s/\;/\\;/g;

                   # $DirName =~ s/\(/\\(/g;

                   # $DirName =~ s/\)/\\)/g;

                   # $DirName =~ s/\ /\\ /g;

                

                   $ftp->rmdir ( "$DirName", 1 );

                   $ftp->rmdir ( "$DirName", 0 );

                

                   if ( @{ lsa ( "$DirName", 0 ) } ) {

                   # if ( not Exists ( "$DirName", 0 ) ) {

            print "Directory <$DirName> failed to delete.  Bummer dude!\n";

                                lsa ( "$DirName", 1);

                                print "\n";

                   # } else {

            # print "Directory <$DirName> was deleted\n";

         }

                

                } else {

                   print "Unknown Type was detected <$$DelPtr{'Type'}>.  Existing 
loop\n";

                   return 0;

                }

                

   }

   $ftp->rmdir ( "$Target", 1 );

   # print "\n";

}



Reply via email to