Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-02-2009, 04:51 PM   #1
LQ Newbie
Registered: May 2007
Location: LA
Distribution: Gentoo, OpenSolaris and FreeBSD
Posts: 19

Rep: Reputation: 0
Perl Net::FTP problem

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:
use Net::FTP;

$ftp = Net::FTP->new("", Debug => 1, Passive => 1)
    or die "Cannot connect to $@";

   or die "Cannot login ", $ftp->message;                                                                       

    or die "can\'t go binary ", $ftp->message;

#in case it's already there

    or die "put failed ", $ftp->message;
Here's debug output:
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.
Old 06-02-2009, 05:45 PM   #2
LQ Newbie
Registered: May 2009
Posts: 1

Rep: Reputation: 0
Try running it with Debug set to 3 and see what you get. You may not have permissions to write to the directory or is using the wrong port.
Old 06-02-2009, 05:54 PM   #3
LQ Newbie
Registered: May 2007
Location: LA
Distribution: Gentoo, OpenSolaris and FreeBSD
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks for the reply. Setting debug to 3 gives the same output (the docs don't indicate that there are varying debug levels in either Net::FTP or the Net::Cmd package which it uses). It isn't a permissions issue because I'm able to write to both ftp servers using an ftp client on my machine. It can't be the wrong port because it's connecting fine and doing everything ok except sending a file.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Net::FTP - LIST Causes Connection Hang taylor_venable Programming 0 01-05-2006 03:59 PM
Urgent Help: Perl FTP Script Using NET::FTP xboxter Programming 8 05-16-2005 06:57 PM
perl and Net::FTP question Tomasfuego Programming 0 12-17-2003 08:13 AM
perl, Net::Ftp, and Novell file modification time neo77777 Programming 0 01-30-2003 09:41 PM
perl NET::FTP binary mode lackluster Programming 5 07-18-2002 06:30 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration