Solved

PERL and ftp

Posted on 2004-09-30
6
380 Views
Last Modified: 2006-11-17
Hi All,

I am trying to write a script that will ftp files from a Linux PC, to a Web Server.  I wrote a PERL script, and when I execute it, first of all, it takes quite a while to send a 1 kb file, and then, when I check the destination directory after words, the file is listed there but is 0 kb, and is completely empty.  I've been trying to send a txt file just to work the bugs out, but I am completely stumped.  I've tried binary mode and Ascii (I'm really not sure when to use either of them) and still the same results.  Here is the script I wrote:

#!/usr/bin/perl
use CGI;
use Net::FTP;

$LOGIC="xxx.xxx.xxx.xxx"; # destination i.p. address actual address is in my script
$file="brian.txt"; #file I want to transfer

 $ftp = Net::FTP->new($LOGIC, Debug => 0);
 $ftp->login("username","password"); #actual username and password is in my script

 $ftp->put($file);
 $ftp->quit;
exit();
0
Comment
Question by:wxman1
6 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 12191407
Let's start by enabling debuging and printing out errors.

$ftp = Net::FTP->new($LOGIC, Debug => 1);
$ftp->login("username","password") or die 'login', $ftp->message;

$ftp->put($file) or die 'put', $ftp->message;
$ftp->quit;
0
 
LVL 12

Expert Comment

by:geotiger
ID: 12191507
I think that it might be due to the put could not find the file. It is better to use full path in $file such as

$file = "/my/path/to/brain.txt";
0
 

Author Comment

by:wxman1
ID: 12191567
Okay,

After turning on the debugging, this is what came back:


Net::FTP>>> Net::FTP(2.72)
Net::FTP>>>   Exporter(5.57)
Net::FTP>>>   Net::Cmd(2.24)
Net::FTP>>>   IO::Socket::INET(1.27)
Net::FTP>>>     IO::Socket(1.28)
Net::FTP>>>       IO::Handle(1.23)
Net::FTP=GLOB(0x9e2570)<<< 220 logic-web-b FTP Server (vftpd 1.31) ready.
Net::FTP=GLOB(0x9e2570)>>> user username
Net::FTP=GLOB(0x9e2570)<<< 331 Password required for username.
Net::FTP=GLOB(0x9e2570)>>> PASS ....
Net::FTP=GLOB(0x9e2570)<<< 230 User username logged in.
Net::FTP=GLOB(0x9e2570)>>> ALLO 11
Net::FTP=GLOB(0x9e2570)<<< 200 ALLO command ignored.
Net::FTP=GLOB(0x9e2570)>>> PORT 10,0,2,55,210,30
Net::FTP=GLOB(0x9e2570)<<< 200 PORT command successful.
Net::FTP=GLOB(0x9e2570)>>> STOR brian.txt
Net::FTP=GLOB(0x9e2570)<<< 150 Opening ASCII mode data connection for brian.txt
putOpening ASCII mode data connection for brian.txt

Thats what came up on the screen.  Any suggestions?
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

Author Comment

by:wxman1
ID: 12192198
geotiger

I added the full path, still having the same problem though
0
 
LVL 18

Accepted Solution

by:
kandura earned 50 total points
ID: 12194588
have you tried Passive mode yet?
It sounds like the data connection isn't made correctly, which might be due to firewall settings, or the ftp server configuration.

add "Passive => 1" to your Net::FTP->new call.
0
 

Author Comment

by:wxman1
ID: 12202997
Passive Mode!  I completely forgot!  That did the trick thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading fields from the text file. 4 97
batch script for automated email 12 111
Union rows in array that have common elements (Part 2) 4 75
Perl string filter 5 79
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question