I've got a perl cron job that runs every week and needs to upload output to an ftp server. I've thought about using a shell script, but then found Net::FTP via cpan. I've had great luck with Net::Mail so I figured Net::FTP would work just as well. Unfortunately no. It logs in fine, change directory works, delete file works, but when I try to upload a file via the "put" command, no dice. I've tried the most simple test but it always gives output "226 transfer complete" but the file on the ftp server contains zero bytes. Google searching has uncovered quite a few other people who've run into this, but no solutions.
I've tried two different FTP servers, I've tried specifying the source file name with and without the full path but either way gives the same result (it seems like it could be a source file issue since the file name shows up on the remote server but with zero bytes, like it gets the file name but not the actual file). Anyone here using it successfully? My skills are not up to debugging Net::FTP or the packages it relies on unfortunately.
Here's my code:
Code:
use Net::FTP;
$ftp = Net::FTP->new("ftp.testserver1.com", Debug => 1, Passive => 1)
or die "Cannot connect to ftp.testserver1.com: $@";
$ftp->login("anon",'1234')
or die "Cannot login ", $ftp->message;
$ftp->binary()
or die "can\'t go binary ", $ftp->message;
#in case it's already there
$ftp->delete("test.txt");
$ftp->put("/home/me/DataFile.txt",'test.txt')
or die "put failed ", $ftp->message;
Here's debug output:
Code:
Net::FTP>>> Net::FTP(2.77)
Net::FTP>>> Exporter(5.58)
Net::FTP>>> Net::Cmd(2.29)
Net::FTP>>> IO::Socket::INET(1.29)
Net::FTP>>> IO::Socket(1.29)
Net::FTP>>> IO::Handle(1.25)
Net::FTP=GLOB(0x840ab14)<<< 220 Serv-U FTP Server v7.4 ready...
Net::FTP=GLOB(0x840ab14)>>> USER 40300795
Net::FTP=GLOB(0x840ab14)<<< 331 User name okay, need password.
Net::FTP=GLOB(0x840ab14)>>> PASS ....
Net::FTP=GLOB(0x840ab14)<<< 230 User logged in, proceed.
Net::FTP=GLOB(0x840ab14)>>> TYPE A
Net::FTP=GLOB(0x840ab14)<<< 200 Type set to A.
Net::FTP=GLOB(0x840ab14)>>> DELE test.txt
Net::FTP=GLOB(0x840ab14)<<< 250 DELE command successful.
Net::FTP=GLOB(0x840ab14)>>> PASV
Net::FTP=GLOB(0x840ab14)<<< 227 Entering Passive Mode (138,108,54,156,6,102)
Net::FTP=GLOB(0x840ab14)>>> STOR test.txt
Net::FTP=GLOB(0x840ab14)<<< 150 Opening ASCII mode data connection for test.txt.
Net::FTP=GLOB(0x840ab14)<<< 226 Transfer complete. 0 bytes transferred. 0.00 KB/sec.
Net::FTP=GLOB(0x840ab14)>>> QUIT
Net::FTP=GLOB(0x840ab14)<<< 221 Goodbye, closing session.