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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.