I'm having the same problem except it connects to the remote server, and prints at the "Connected to $host" line, but then stops completely just before or during the 'get' command. This is when run from the browser. It works perfectly from the command line. I don't understand!

I'm a bit of a newbie, and so I'm not sure on how to generate debug information in the browser window. Help!? I've tried all the suggestions I've seen on here so far (I think) with no joy - including the passive settings, and I'm not sure what to do next!

Basically I'm trying to automate the movement of a file from one server (FTP) to another (SFTP) on our system. I know th path to file and I'm not using cwd() as it works fine in command line...would cwd() help?

Any help would be hugely appreciated! I haven't even gotten to any possible problems with Net::SFTP::Foreign!

Here's the code:

#!/usr/bin/perl $|=1; print "Content-Type: text/plain\n\n"; use warnings; use strict; use Net::SFTP::Foreign; use Net::FTP; my $host = "xxxxxxxxxxxxxxxxxx"; my $user = "yyyyyyyyyyy"; my $password = "zzzzzzzz"; my $securehost = "aaaaaaaaaaaaaaaaa"; my $secureuser = "bbbbbbbbbbbbbb"; my $securepassword = "cccccccccccccc"; my $timeout = "120"; my ($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(tim +e); $mon++; $year += 1900; my $handle = $year . $mon . $mday; my $ftp = Net::FTP->new($host, Debug=>3, Timeout=>120, Passive=>1); $ftp->error and die "unable to connect to remote host: " . $ftp->error +; $ftp->login($user,$password); print "Connected to $host\n"; $ftp->get("/remote/path/to/file/file.txt", "/local/path/to/file/file_$handle.txt") or die "file transfer failed: " . $ftp->error; print "file.txt transferred locally and filename changed to file_$hand +le\n"; $ftp->quit(); my $sftp = Net::SFTP::Foreign->new($securehost, user=>$secureuser, pas +sword=>$securepassword, timeout=>$timeout); $sftp->error and die "unable to connect to remote host: " . $sftp->err +or; print "Connected to $securehost\n"; $sftp->put("/local/path/to/file/file_$handle.txt", "/remote/path/to/fi +le/file_$handle.txt") or die "file transfer failed: " . $sftp->error; print "file_$handle uploaded to $securehost at $hr:$min."; $sftp->disconnect(); exit;

In reply to Re: Net::FTP via CGI mystery by FuzInc
in thread Net::FTP via CGI mystery by George_Sherston

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.