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

Hello:
I am new on this site, however I have been programming in perl for over 2 years now.
Last friday when tracking an error on my code I found a very extrange behaviour when using the function "put" from the Net:FTP module. The code is something like this:

$self->{ftp}->put($origin, $target) or $msg = $self->{ftp}->message(), $cod = $self->{ftp}->code(), print "$cod: $msg\n", return 1;

Looks is ok and works pretty well until the put failed for the first time. Here is the curious behavior, if you debug this piece of code and just before calling the put function you delete the $origin file and calls the put function then it will return an error and execute the "or" part. However the code and message returned in $msg and $cod is: "250: CWD command successful".

So I would like to know if there is any kind of bug reported and fix it or is this as expected. Have anyone had the same problem?

Thank you very much,
Francisco Jaen

20040927 Edit by Corion: Added code tags, formatting

Replies are listed 'Best First'.
Re: FTP wierd return.
by NetWallah (Canon) on Sep 27, 2004 at 13:15 UTC
    From the Net::FTP docs:

    Put() Returns REMOTE_FILE, or the generated remote filename if REMOTE_FILE is not given.

    So, what you are getting is NOT an error.

    The code corresponds to the FTP Server status 250:

    250 Requested file action okay, completed.

    I'm not sure why the message() does not correspond to the code() - perhaps the programmer makes it correspond only in error cases .. that would be a minor bug, to me.

        Earth first! (We'll rob the other planets later)

Re: FTP wierd return.
by shenme (Priest) on Sep 27, 2004 at 22:13 UTC
    Seems to me you are describing the situation where you have a _local_ error, and the messages you see are from the last Net::FTP call. That is, before Net::FTP ever got around to trying an FTP operation it died without clearing out any previous error statuses.

    I'm guessing here, but comparing with the situation you checked with, where the local file is missing. See the following snip from Net/FTP.pm:

    unless(sysopen($loc, $local, O_RDONLY)) { carp "Cannot open Local file $local: $!\n"; return undef; } }
    The put() call could return undef without setting either of the Net::FTP error variables. I don't know if the docs say you should check $! in this situation or not. This behavior does seem kinda hard to deal with.