Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Delete folders via FTP

by new_monk (Sexton)
on Feb 06, 2004 at 22:01 UTC ( [id://327234]=perlquestion: print w/replies, xml ) Need Help??

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

How would you delete folders via an ftp connection? I am having trouble getting it done. Should I try it via telnet? I have tried rmdir and delete but still can not get them deleted. I am able to rename them but when I try to delete them I get a "Do not specify an existing file" even though I was able to rename it.

Replies are listed 'Best First'.
Re: Delete folders via FTP
by Abigail-II (Bishop) on Feb 06, 2004 at 22:04 UTC
    The command to delete a directory is called rmdir. See the Net::FTP manual page.

    Abigail

      Thanks for your reply. Here is my code and the errors:
      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 Messa +ge> /ep005 /egate/client/iq/{E9424A48-0086-11D7-AE05-AD16EA76821A}: D +o 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. I can rename the folders too.
        Are you sure you only attempt to remove empty directories? To me it seems you are trying to delete all entries in /ep005/egate/client/iq/, regardless whether they are files, non-empty directories or empty directories.

        But then, I only looked at your program briefly. It's just a wad of undocumented code, without explaining what it is supposed to do. The error message is not a Perl error.

        Abigail

Re: Delete folders via FTP
by z3d (Scribe) on Feb 07, 2004 at 13:40 UTC
    Assuming (I know) that you *are* using a perl based method here, such as Net::FTP or varients, are you sure the directory is empty? That too can throw an error...



    "I have never written bad code. There are merely unanticipated features."
      If the directory does not have anything in it then it would throw an error? In order to delete a folder there has to be some file or other sub directory in order for rmdir() to work?
        Reverse - you can't delete a dir if it still has content. I don't see where you validate in your code that the directory is empty - do you know it is empty already?



        "I have never written bad code. There are merely unanticipated features."
      Thanks for your reply. Here is my code and the errors:
      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 Messa +ge> /ep005 /egate/client/iq/{E9424A48-0086-11D7-AE05-AD16EA76821A}: D +o 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 "{}" bracket. I tried using an asterick too but to no avail. I can rename the folders too.
Re: Delete folders via FTP
by Berik (Sexton) on Feb 06, 2004 at 23:16 UTC
    I think perlmonks is not the right place to ask this kind of question. Did you try the FAQ of you Internet Service Provider? maybe they can help you out. If you question is perl related you should follow Abigail's advice and read the documentation of Net::FTP. Good luck.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://327234]
Approved by footpad
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-03-29 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found