Hi Folks
I have a pretty specific question about standard out handling with Net::FTP.

I want to run a script in a verbose mode to collect lots of information at each step of an ftp session. For each step in the FTP process I want to print a message to standard output. A truncated example is included below.

When I try to do this, the script executes with no errors but I don't know what is actually happening during each step of the ftp process - the standard output does not appear to be there for you to see or collect.

Does Net::FTP open up a seperate shell and run the ftp session through this? This might explain why I cannot capture the standard output from the ftp session from each step of the subroutine.

Should we be using Net::Cmd to capture these responses? Looking at the documentation there is mention of a series of six subroutines: CMD_INFO, CMD_OK, CMD_MORE, CMD_REJECT and CMD_ERROR ,correspond to possible results of response and status. The sixth is CMD_PENDING. However I don't see an example of how these might be used. For chuckles and grins I have read through the associated perlmonks messsages, CPAN documentation and man pages on Net::FTP and Net::Cmd and the Perl Cookbook

Finally I did see the Debug flag in the libnet documentation and we are trying this out. But again, does this faithfully pipe back the messages from the ftp server or is it simply the Net::FTP module's interpretation of the server response?

Here is a copy of the contents of a subroutine that we are using here. We have used strict and the -w flag in another portion of our script, so the code does pass with these tests. We do realize that we could have used 'or die' but we planned to do something that would be a wee bit more extensive and suitable to our needs

...omitted for clarity... print "Connecting to $url ... " ; if ($ftp = Net::FTP->new($url)) { $opt_v and print " as $userName ..." ; if ($ftp->login($userName,$password)) { print "\n" ; $opt_v and print "Changing to directory $sourceDir ..." ; if ($ftp->cwd($sourceDir)) { $opt_v and print "Getting $flatFile ... " ; if ($ftp->get($flatFile)) { print "done"; } else { print "failed to get file\n" ; } } else { print "failed to change directory\n" ; } } else { print "failed to login\n" ; } } else { print " connection failed\n" ; } $ftp->quit;

Thanks in advance for the help!

MadraghRua
yet another biologist hacking perl....


In reply to Net::FTP and standard output by MadraghRua

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.