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

Im using Net::sftp::foreign to maintain files across several hundred client machines. Im running into an issue where 'rename' creates the dest file but leaves a copy behind. ( i have to use rename as there isn't a 'move' command ).

I started trapping this specific issue as it comes up very regularly (10-20% - but measured against thousands of files its pretty annoying). When I try to use 'remove' to get rid of the 'dest' copy I get a TRUE (1) return but the file is still there!

Questions: what's a better approach? Is there an error that I should be looking at besides $sftp->error ?
  • Comment on net::sftp::foreign->rename / remove issues

Replies are listed 'Best First'.
Re: net::sftp::foreign->rename / remove issues
by salva (Canon) on Oct 08, 2007 at 20:17 UTC
    The SFTP protocol has native support for the RENAME operation, it is not something emulated by Net::SFTP::Foreign, so if it leaves the old file around it is probably the server fault.

    Can you post your code? Which SSH software are you using on the server side?

      To be clear: when you say 'server' - do you mean the box where the files are being moved / renamed or where the commands are originating from?

      Also - why would the 'remove' command report success when it wasn't successful?
        when you say 'server' - do you mean the box where the files are being moved

        Yes!

        Also - why would the 'remove' command report success when it wasn't successful?

        I have no idea, I can not see any error on the module code.

        I have just uploaded a new version of the module to CPAN that supports better debugging. Can you install that version, add...

        $Net::SFTP::Foreign::debug = 25;
        at the beginning of your script, reproduce the problem and send me the debugging output for that execution (and the script, of course!)
Re: net::sftp::foreign->rename / remove issues
by chrism01 (Friar) on Oct 09, 2007 at 06:53 UTC
    If the remote boxes are some kind of Unix, you can delete (ie unlink) a file, but if it is still/held open by another (prob local ie on remote box) process, it will still actually 'exist' until the other process closes it.

    Cheers
    Chris