packetstormer has asked for the wisdom of the Perl Monks concerning the following question:
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::FTP output to array
by Perlbotics (Archbishop) on Aug 18, 2011 at 09:31 UTC | |
by packetstormer (Monk) on Aug 18, 2011 at 10:39 UTC | |
by packetstormer (Monk) on Aug 18, 2011 at 09:45 UTC | |
|
Re: Net::FTP output to array
by Khen1950fx (Canon) on Aug 18, 2011 at 10:55 UTC | |
by packetstormer (Monk) on Aug 18, 2011 at 14:16 UTC |