Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Welcome to the Monastery

Need help deleting IQ Folders

by new_monk (Sexton)
on Feb 04, 2004 at 18:19 UTC ( #326545=perlquestion: print w/ replies, xml ) Need Help??
new_monk has asked for the wisdom of the Perl Monks concerning the following question:

I too am new to Perl and could use some assistance. I have to telnet into a server and delete the following directory structure(e*Gate Intelligent Qs) under iq...

$usrid:/ep005/egate/client/iq>ls {2CE791F8-B956-11D7-8A47-D2047591D9E7} {E966E092-0086-11D7-AE05-ABCC42 +0F384C} {2D3A2FE4-B956-11D7-AA01-9928386F0C64} {E9684022-0086-11D7-AE05-B56CD2 +0DA8C8} {2EB061E0-B956-11D7-8FAD-A2B3FC810BD6} {E9699C1A-0086-11D7-AE05-DE7A18 +3014AC} {E9404D1A-0086-11D7-AE05-C74CFA34F9DD} {E96B2BC0-0086-11D7-AE05-B76DF2 +2F3513}

I have not been successful in accomplishing this. In my script, once I am in the iq directory I tried

$ftp->rmdir("/ep005/egate/client/iq/$folders"); $ftp->delete("/ep005/egate/client/iq/{*}"); system("rm -r {*}"); system("rm -r *");

I pull in a list of the items into an array, sort the list then I tried running any of the statements above and neither seem to work. When I telnet manually into the server I can run this command to delete the structures

rm -r {*}

What command would delete each one or all of them under the iq directory?

Edited by Chady -- added code tags.

Comment on Need help deleting IQ Folders
Select or Download Code
Re: Need help deleting IQ Folders
by valentin (Abbot) on Feb 04, 2004 at 18:25 UTC
    See perldoc File::Path
    use File::Path; rmtree(['foo/bar/baz', 'blurfl/quux'], 1, 1);
      I tried but get error message for this code:
      foreach $folder (@iqfolder_arr) { print("Printing from inside the last foreach but before rmdir: $fol +der\n"); $ftp_disco->rmtree(['/ep005/egate/client/iq/$folder'], 1, 1) || die + "Error: @{[ $ftp_disco->message ]}\n"; }

      Can't locate object method "rmtree" via package "Net::FTP" (perhaps you forgot t o load "Net::FTP"?) at C:/Perl/eg/data/ line 86.

      so I also tried:
      foreach $folder (@iqfolder_arr) { print("Printing from inside the last foreach but before rmdir: $fol +der\n"); rmtree(['/ep005/egate/client/iq/$folder'], 1, 1) || die "Error: @{[ + $ftp_disco->message ]}\n"; }

      but got this error: Error: Opening data connection for .. Transfer complete.
        you need  use File::Path; in front of your script to import the function rmtree. but sure this will not work with ftp. It looks you try with Net::Ftp ftp is not telent. Within ftp try rmdir.
        $ftp->rmdir('your_directory', 1);
        but it is untested.
Re: Need help deleting IQ Folders
by ysth (Canon) on Feb 04, 2004 at 19:32 UTC
    I'm kind of confused. It sounds like you want to automate telneting into a server and deleting some files, but in your example, you say "$ftp" (which presumably isn't a telnet object) and "system" (which deletes files on your local system, not on a remote one).

    Perhaps you want to look at using Net::Telnet's cmd method?

      Telnet is highly insecure and should never be recommended. Use SSH whenever possible!
      I use ftp to get some log files then remove or delete them from the server which works good. I am trying to do the same with the folders (ie {FJWEOI-3HEJW....}).
Re: Need help deleting IQ Folders
by new_monk (Sexton) on Feb 04, 2004 at 23:03 UTC
    Here is the code:
    use File::glob; use strict; use Net::FTP; use File::Copy; use File::Path; use File::Remove; my $host_disco = "censored"; my $user_disco = "censored"; my $password_disco = "censored"; my $ftp_disco = ""; my $dir = "/"; my $diriq_disco = "/ep005/egate/client/iq"; my @iqfiles_disco = ""; my $file1 = ""; my @iqfolder_arr = ""; my $folder = ""; my $iqfolder = ""; my $folder1 = ""; my $count = 0; #------------------------- $ftp_disco = Net::FTP->new($host_disco) or die "Can't open $host_disco +: $@\n"; $ftp_disco->login($user_disco, $password_disco) or die "Couldn't login +: @{[ $ftp_disco->message ]}"; $ftp_disco->ascii(); $ftp_disco->cwd($dir) or die "Couldn't cwd to $dir: @{[ $ftp_disco->me +ssage ]}\n"; $ftp_disco->cwd($diriq_disco) or die "Couldn't cwd to $diriq_disco: @{ +[ $ftp_disco->message ]}\n"; @iqfolder_arr = $ftp_disco->ls; foreach $folder1 (@iqfolder_arr) { $iqfolder_arr[$count] =~ s/ //g; $iqfolder_arr[$count] =~ s/\n//g; $count++ } foreach $folder (@iqfolder_arr) { my $dirpath = '/ep005/egate/client/iq/'; $dirpath .= $folder; print($dirpath); $ftp_disco->rmdir($dirpath) || die "FTP Message> @{[ $ftp_disco->mess +age ]}\n"; } $ftp_disco->close(); $file1 = ""; sleep(2); print("Disco IQs have been cleared.\n"); #-----------------------------------#
    Error Message:
    /ep005/egate/client/iq/{E9424A48-0086-11D7-AE05-AD16EA76821A}FTP Message> /ep005 /egate/client/iq/{E9424A48-0086-11D7-AE05-AD16EA76821A}: Do not specify an exist ing file.
    Press Enter to continue

    Seems like I have the right idea and the correct methods maybe but I am not sure if maybe the folder that I am trying to remove maybe causing the problem because of the "{}" brackets. I tried using an asterick too but to no avail.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://326545]
Approved by blue_cowdawg
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-04-19 00:44 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (474 votes), past polls