You should check the return codes after each call to a Net::FTP method (actually, the code I present below should work for just about any Net:: module that comes with libnet, not just Net::FTP). See the below code:
use Net::FTP; $ftp = Net::FTP->new("www.somedomain.org"); check_net_err($ftp); $ftp->login("user","password"); check_net_err($ftp); $ftp->cwd("/pages"); check_net_err($ftp); $ftp->get("defhome.htm"); check_net_err($ftp); $ftp->quit; sub check_net_err{ my $net=shift; if(!defined $net){ die "Net:: object not defined $!"; }else{ if((!$net->ok())||($net->code() >= 400)){ die "Net:: error ".$net->code()." : ".$net->message(); } } }
You can set the Debug flag on the Net::FTP->new call and get a trace of the session dumped to STDERR.
my $ftp = Net::FTP->new("www.somedomain.org",Debug=>1);
example output of Net::FTP w/ Debug=>1
Net::FTP: Net::FTP(2.40)
Net::FTP:   Exporter
Net::FTP:   Net::Cmd(2.12)
Net::FTP:   IO::Socket::INET(1.24)
Net::FTP:     IO::Socket(1.25)
Net::FTP:       IO::Handle(1.21)

Net::FTP=GLOB(0x81f20e4)<<< 220 www.somedomain.org FTP server (Version wu-2.6.0(1) Thu Oct 21 12:27:00 EDT 1999) ready.
Net::FTP=GLOB(0x81f20e4)>>> user someusername
Net::FTP=GLOB(0x81f20e4)<<< 331 Password required for someusername.
Net::FTP=GLOB(0x81f20e4)>>> PASS ........
Net::FTP=GLOB(0x81f20e4)<<< 230 User someusername logged in.
Net::FTP=GLOB(0x81f20e4)>>> CWD /pages
Net::FTP=GLOB(0x81f20e4)<<< 550 /pages: No such file or directory.
Net:: error 550 : /pages: No such file or directory.
Net::FTP=GLOB(0x81f20e4)>>> QUIT
Net::FTP=GLOB(0x81f20e4)<<< 221-You have transferred 0 bytes in 0 files.
Net::FTP=GLOB(0x81f20e4)<<< 221-Total traffic for this session was 269 bytes in 0 transfers.
Net::FTP=GLOB(0x81f20e4)<<< 221-Thank you for using the FTP service on www.somedomain.org.
Net::FTP=GLOB(0x81f20e4)<<< 221 Goodbye.

You may want to check out the earlier post Trapping errors from NET::Ftp for some other approaches.

In reply to Re: use of ftp in libnet package by lhoward
in thread use of ftp in libnet package by dyfn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.