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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hello,

Yeah, the Net::FTP docs seem kind of lacking on this information. While I haven't tried the following answers out for myself, I got them from a program which works, so I'd assume they are correct:

1. when FTP->new() call was invoked

Well, this is just a typical constructor, the FTP code hasn't tried to do anything with a remote system yet. However, you can check for the return value of the login() call, like so:
my $max_tries = 5; my $tries = 0; # login() returns false, if unsuccessful while( ! $ftp->login('anonymous', 'me@myself.com' ) { $tries++; die "We tried $tries times, but cannot connect!\n" if $max_tries == +$tries; warn "Attempt $tries: Could not connect, trying again.\n"; } print "Yay! We logged in!\n";

2. when all the files were ftp'd. i.e., at FTP->quit

The return value of $ftp->quit would actually tell you if the quit() call was successful or not, which isn't what I think you're worried about.

What you'd need to do is check the call of each put() method:
$ftp->put("$dir/$file1") or die "FTP did not succesfully upload $dir/ +$file!";

Or, if you don't actually want to die, you could also just set a flag if the put fails. Just like login(), put returns a true value if successful, false otherwise.

Hope that helps!
-Eric

Update: Yeah, what derby said, he managed to type it in quicker then myself, and I like his eval trick :-)

--
Lucy: "What happens if you practice the piano for 20 years and then end up not being rich and famous?"
Schroeder: "The joy is in the playing."

In reply to Re: ftp return value by andreychek
in thread ftp return value by arajani

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2022-05-20 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (73 votes). Check out past polls.

    Notices?