#!/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(time); $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_$handle\n"; $ftp->quit(); my $sftp = Net::SFTP::Foreign->new($securehost, user=>$secureuser, password=>$securepassword, timeout=>$timeout); $sftp->error and die "unable to connect to remote host: " . $sftp->error; print "Connected to $securehost\n"; $sftp->put("/local/path/to/file/file_$handle.txt", "/remote/path/to/file/file_$handle.txt") or die "file transfer failed: " . $sftp->error; print "file_$handle uploaded to $securehost at $hr:$min."; $sftp->disconnect(); exit;