Backticks don't capture STDERR. You'd need to redirect STDERR on top of STDOUT for lftp as lftp uses STDERR for much of its interface.

Try this:

my $CLIENT = "lftp"; my $connectionString = "" . $CLIENT . " -d -f script.ftp 2>&1"; my $result = `$connectionString` or die "\nERROR running $CLIENT: $!"; return $result;

I make no guarantees, but I did install lftp just to test this theory and look at this which shows STDERR being used:

[chris@pineapple ss64]$ >bar [chris@pineapple ss64]$ lftp -d -f foo > bar ---- Resolving host address... ---- 1 address found: 64.131.79.110 Password: [chris@pineapple ss64]$ cat bar [chris@pineapple ss64]$ lftp -d -f foo > bar 2>&1 Password: [chris@pineapple ss64]$ cat bar ---- Resolving host address... ---- 1 address found: 64.131.79.110 [chris@pineapple ss64]$

As a side note, I hope you're using SFTP or HTTPS (both of which modern versions of lftp support) if you're not using an anonymous connection. I don't use plain-text FTP with authenticated accounts, and I recommend others don't. Without getting into too many specifics about statistics, let's say it's common in the security department of a web hosting company to deal with customers whose hosting account credentials were stolen by malware or sniffing. It may be a small portion of customers who ever have a breach, but compromised passwords are a fairly common sort of breach. Use SFTP or scp if you can, and use HTTPS when possible if logging into a web app you actually care a lot about.

BTW, none of this is really Perl-specific beyond 'Backticks don't capture STDERR.'. Then again, those backticks are reminiscent of shell backticks which work the same way, so that's not even that Perl-specific.


In reply to Re: Perl die after executing external program by mr_mischief
in thread Perl die after executing external program by aullah

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.