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

Hello Wise Monks:

Let me explain a situation I am having a problem on a perl module. This module sends via FTP a file to a directory and then moves (rename) that file to another directory with another name, this last step is also done via ftp.

In order to do this I use the FTP.pm module. However once in a while I received an error message from the rename operation when doing the move part, I wrote down logs in the code to see what happens and I get 550 FTP code Error. The code I use is the followinig:

unless ($returncode = $self->{ftp}->rename($oldName, $newName)) { $msg=$self->{ftp}->message(); $code=$self->{ftp}->code(), MercMsg::RtrReportInfo(10001,"error el rename del fichero", "ft +p message",$code.": ".$msg,"10005"); return 0; }

In my case the rename returns an error code (see bellow) but the file has been move correctly, the error message is:

Run Time Desc: 550: rename: No such file or directory.

My question is: Does anyone know why this happen? Is the rename operation atomic like a transaction? This has happen a couple of times and the file has been moved in both ocasions correctly but the ftp rename has return error.

EDIT: -----------

The target directory exists for sure due to fact that there are anothter 3 instances running at the same time (moving other files) and didn't have that problem. The files in the target directory are being taken away once in a while, it may be that the target file is taken after the rename is done but before the file handle is closed (I am not sure about this) by thte rename. Also the file hasa been correctly moved in any case. Thanks for answer bart. :-)

EDIT2: -----------

This has happen also on a NFS copy a couple of months ago.

The original file is not there anymore after the error has been return.

Our system is mounted on a Digital Tru64 OS

Francisco Jaen

Replies are listed 'Best First'.
Re: Question about FTP.pm rename operation
by bart (Canon) on Oct 29, 2004 at 08:04 UTC

    It could be that the directory you're trying to move the file to, doesn't exist. Or at least, isn't for the FTP server where you think it ought to be. That would cause that kind of error message.

    Perhaps you could upload the file directly where you want it to be, but with a temporary, unique name?

    I don't think it's likely that the file, after you uploaded it, doesn't exist yet/any more.

Re: Question about FTP.pm rename operation
by steves (Curate) on Oct 29, 2004 at 09:25 UTC

    Do you know what OS and/or FTP software the FTP server is running? This could be a server specific bug of some sort.

    Regarding your "is it atomic" question: rename is implemented by two lower level FTP commands on all servers I'm aware of. first an RNFR is sent by the client to the server. If that succeeds, then an RNTO is sent.

    You say the target file is there even when you get the error. How about the original? Is it still there? It may be that the way the server implements rename, it's able to create the new file but not remove the old one, although that seems pretty unlikely if you put the original one there. I have seen some flaky NFS mounted disks give a "no such file or directory" error when they hit other issues.

Re: Question about FTP.pm rename operation
by nimdokk (Vicar) on Oct 29, 2004 at 09:55 UTC
    I've seen something very similar happen with a ProFTP server I connect to (not sure of the OS version - should be a *nix but I don't know which off hand). When I see this, I am doing everything straight from the commandline and while I do see the error message, the command is in fact successful.