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:
print "Content-Type: text/plain\n\n";
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
$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
print "Connected to $host\n";
or die "file transfer failed: " . $ftp->error;
print "file.txt transferred locally and filename changed to file_$hand
my $sftp = Net::SFTP::Foreign->new($securehost, user=>$secureuser, pas
$sftp->error and die "unable to connect to remote host: " . $sftp->err
print "Connected to $securehost\n";
or die "file transfer failed: " . $sftp->error;
print "file_$handle uploaded to $securehost at $hr:$min.";
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>
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
Want more info? How to link or
or How to display code and escape characters
are good places to start.