Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Need Net::FTP rmdir time out help

by Todd Chester (Scribe)
on Feb 01, 2017 at 08:00 UTC ( [id://1180737]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Perl Monks,

Strawberry Perl 5.24.0.1 for Windows.
$ rpm -qa \*vsftp\* vsftpd-3.0.3-3.fc25.x86_64
I am trying to recursively delete directories on an FTP server (vsftp) with Net::FTP with Windows with Perl 5
$ftp->rmdir ( "${Ordered_List[$Index]}", 1 );
Problem:  $ftp->rmdir doesn't wait for the operation to finish.  And if I go on to another FTP command of any type before rmdir finishes, the rmdir command will terminate, leaving the directory, or what is left of it, in place.  I am having to guess at how long to wait with the "sleep" command.

How do I wait for rmdir to finish and not guess at it?  The directory size could be a big as 30 GB in the future.

Many thanks,
-T

Replies are listed 'Best First'.
Re: Need Net::FTP rmdir time out help
by salva (Canon) on Feb 01, 2017 at 08:37 UTC
    Well, if the remote rmdir operation is reliably terminated every time you reconnect to the machine then, you can just check if the directory exists and in that case restart the deletion:
    while(1) { my $ftp = Net::FTP->new(...); defined $ftp->mdtm($dir) or last; $ftp->rmdir($dir); sleep 10; }
      Hmmmm. Maybe I open a second connection to the server and check in a loop to see if the directory still exists or is gone. That "should" (watch the weasel word) keep the original connection from terminating.

        Or perhaps run (via rsh) a script to handle the deletes? It could use a semaphore file to indicate it is still running. Your other process could check for the presence of that file at intervals and continue once it has disappeared.

        But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Re: Need Net::FTP rmdir time out help
by Mr. Muskrat (Canon) on Feb 01, 2017 at 17:53 UTC

    You aren't checking if rmdir succeeded or failed. The docs say: "Unless otherwise stated all methods return either a true or false value, with true meaning that the operation was a success. When a method states that it returns a value, failure will be returned as undef or an empty list."

    How can you be sure that it's being terminated early by the next command?

    Honestly, you haven't provided enough context for us to offer useful advice.

      Problem is that the command instantly terminates and does not wait for the deletion with recurse to complete. The deletions can take up to five minutes to complete. What I am doing now is opening a second connection and looping until the directory disappears. Seems there should be a better way
        Quoting Mr.Muskrat:
        You aren't checking if rmdir succeeded or failed.
        So, instead of
        $ftp->rmdir ( "${Ordered_List[$Index]}", 1 );
        you should do something like
        if ($ftp->rmdir ( "${Ordered_List[$Index]}", 1 )) { say "rmdir succeeded"; } else { say "rmdir failed"; }
        Aside from permission problems, a recursive rmdir could fail if e.g. deleting the contents takes too long.
        Can't you use the first connection for that instead of creating a new one?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 15:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found