Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Perl Net::FTP put() gives little help on errors

by amitsk (Initiate)
on Jan 07, 2010 at 08:02 UTC ( #816043=perlquestion: print w/ replies, xml ) Need Help??
amitsk has asked for the wisdom of the Perl Monks concerning the following question:

I have a simple scenario. I upload a zip file on a disk to some server.


use Net::FTP; my $ftp = Net::FTP->new($server, Timeout=>1800, Passive=>1, Debug=>3); $ftp->login($user, $pswd); $ftp->cwd("files"); $ftp->binary(); $ftp->put("build.zip");

The put() succeeds 9 out of 10 times, but for the 10th time (and this is very random), it throws up.

This, I know is because of: 1. Server closing connection, or 2. Internet link break 3. Unknown

My question is what *really* tells me that put() has failed?

a. I have tried $ftp->message but this is empty.
b. $! as I know is not exactly the way, it tells me 'bad file descriptor'
c. I also used eval() with $ftp->message, but is empty as well

So what gives?


By the way, when I try this on a DOS prompt and stop the ftp server, this is what I get.

ftp bin
200 Type set to I
ftp mput build.zip
mput build.zip? y
200 Port command successful
150 Opening data channel for file transfer.
Netout :Software caused connection abort
421 Server is going offline
Connection closed by remote host.


Notice the last 3 lines, I know exactly what went wrong.
Your help is appreciated.

Comment on Perl Net::FTP put() gives little help on errors
Select or Download Code
Re: Perl Net::FTP put() gives little help on errors
by stefbv (Chaplain) on Jan 07, 2010 at 09:11 UTC

    In the SYNOPSIS of the Net::FTP module almost every method call has a "or die ...", did you try that?

    I don't know if this is relevant, regarding the debug level: "a non-zero value results in copies of all commands and responses also being sent to STDERR." (from the Net::Cmd docs)

    Regards, Stefan.

Re: Perl Net::FTP put() gives little help on errors
by tokpela (Chaplain) on Jan 07, 2010 at 09:45 UTC

    You are not checking for errors.

    This code is untested

    use strict; use warnings; use Net::FTP; my $ftp = Net::FTP->new($server, Timeout=>1800, Passive=>1, Debug=>3) +or die "[Error] UNABLE TO CREATE FTP OBJECT: [$@]"; if ($ftp->login($user, $pswd)) { $ftp->cwd("files"); $ftp->binary(); if (! $ftp->put("build.zip")) { my $ftp_message = $ftp->message; chomp($ftp_message); print "[Error] UNABLE TO PUT FILE - [$ftp_message]\n"; } } else { my $ftp_message = $ftp->message; chomp($ftp_message); die "[Error] UNABLE TO LOGIN TO FTP [$server] USING LOGIN ACCOUNT: +[$user]-[$ftp_message]\n"; }

      Even when checking for errors like having if (! $ftp->put("build.zip")) and getting $ftp_message, the $ftp_message is still empty!

      note, on the cmd window, I am seeing this
      Net::FTP: Unexpected EOF on command channel at C:/Perl/lib/Net/FTP/dataconn.pm line 73
      so question if why is $ftp->message empty?

        A guess here, I found this comment in my version of C:/Perl/lib/Net/FTP/dataconn ($VERSION=0.11) in the abort function.
        # for some reason if we continously open RETR connections and not # read a single byte, then abort them after a while the server will # close our connection, this prevents the unexpected EOF on the # command channel -- GMB
        In this case the code aborts - it does not appear to update the error message.
Re: Perl Net::FTP put() gives little help on errors
by poolpi (Hermit) on Jan 07, 2010 at 12:07 UTC

    Just two suggestions:

    - Try to throttle your ftp connection
    - Attempt to re-run the breaked ftp connection


    hth,
    PooLpi

    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb
Re: Perl Net::FTP put() gives little help on errors
by ruzam (Curate) on Jan 07, 2010 at 14:04 UTC

    I've also found Net::FTP put() unreliable at times. When it fails unexpectedly the message isn't always accurate as you've found, often it contains the message of a previous ftp action which makes it totally useless.

    My work around is to:

    (a) check the result of put()
    (b) if it fails, close the ftp session, and open it again
    (c) put() the file again
    (d) repeat from (a) as many times as you can stand to wait (usually the second time works)

    I've found it doesn't do any good to try resending the file without closing and opening the ftp session first.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-07-24 08:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls