Hello

I am running Net::FTP via a CGI script and while it all works fine the module doesn't return any output to screen to show the user the job ran ok. I have enabled debug=>1 and it dumps the output to the screen when running from the terminal.

Does anyone know how to either redirect a function to an array/string or catch the Net::FTP to one? Code below:

#!/usr/bin/perl use strict; use warnings; use CGI; use Net::FTP; use Expect; my $query = new CGI; my ( $template_type, $logged_in, $cookie ) = get_template( { template_name => "uploadbackup.tmpl", query => $query, type => "locked", permission => { allowed_upload => '*' }, debug => 1, } ); my $query = new CGI; my $server_ip = $query->param('server_ip'); my $server_user = $query->param('server_user'); my $server_pass = $query->param('server_pass'); my $os = $query->param('os'); my $file_to_upload = $query->param('file_to_upload'); # Check the Offsite server input boxes have been filled if( (length($server_ip)==0) || (length($server_user) ==0) || ( +length($server_pass) == 0) ) {my $invalid_server_ip = "Nope - you need to fill all +the boxes!."; $template_type->param('invalid_server_ip' => $invalid +_server_ip); } else { my $ftp_message = upload_file($server_ip,$server_user,$server_pass +,$file_to_upload,$os); $template_type->param('file_to_upload' => $file_to_upload, 'ftp_message' => $ftp_message ); } output_html_with_http_headers $query, $cookie, $template_type->output; sub upload_file { my $login_failed_message = "Login Failed. Please check your us +ername and/or password"; my $ftp_message; my $os = $_[4]; my $ftp = Net::FTP->new($_[0], Debug => 1) or die "Cannot conn +ect to $_[0]"; $ftp->login($_[1],$_[2]) or die $login_failed_message; if($os eq "1") { $ftp->binary(); } $ftp->put($_[3]) or die "get failed ", $ftp->message; $ftp->quit; return $ftp_message; }

In reply to Net::FTP output to array by packetstormer

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.