Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Net::FTP via CGI mystery

by FuzInc (Initiate)
on Sep 04, 2013 at 15:32 UTC ( #1052376=note: print w/replies, xml ) Need Help??

in reply to Net::FTP via CGI mystery

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;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1052376]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2022-05-20 07:15 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (72 votes). Check out past polls.