munu has asked for the wisdom of the Perl Monks concerning the following question:

HI all,

This is my ftp client program which is using Net::FTP module. And I have one webpage from where i am giving the inputs to the perl program.
Inputs are
1. ftp host
2. user name
3. password
4.file name to put or get from ftpserver
5 no. of times i want to repeat the operation.

MY PROBLEM IS
1. this progrm is working fine when I am doing a PUT operation.
BUT WHEN I AM DOING GET OPERATION THE ERROR MESSEGE "ABORTED, DATA CONNECTION CLOSED" IS COMING.The file i requested is present on the ftp server and also the path is correct

When I have captured the packets in ethereal One strange thing i have noticed
1. AFTER FTP HOST SENDS "OPENING ASCII MODE DATA TRANSFER.." PACKET, MY LOCAL PC IS SENDIG "request yoy" and one "request oABOR" packet to the ftp server. and after that ftp connection is closed.

but i don't know the reason why my PC is sending those 2 packets(yyy and oABOR)

when i removed the code for Getting data from the web page and all the necessary variables are hardcoded. For ex.
$ftphost='192.168.100.2'; $user='munu'; $pass='munu'; $file='a.b'; $count =10;
THE CODE IS WORKING FINE FOR BOTH GET AND PUT

I have put the code below for your reference

#!/usr/bin/perl use CGI; use Net::FTP; ######################### my $q = CGI->new(); print $q->header("text/html"); print"\n"; ####################### #Code to get input from the web $buffer; my @pairs; my $pair; my %FORM; $buffer = $ENV{'QUERY_STRING'}; @pairs =split(/&/,$buffer); foreach $pair (@pairs) { (my $name,my $value)=split(/=/,$pair); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $value; } ############################ $ftphost=$FORM{serverip};#ftp host $user=$FORM{user};#username $pass=$FORM{pass};#password $file=$FORM{file};#filename $count = $FORM{count};#no. of times to get the file or no. of ftp con +nections print $ftphost, $user, $pass, $file, $count; $!=1; $c=1; while ($count >= 1) { $ftp = Net::FTP->new($ftphost, Debug => 1,Hash=>1); ############################################## #or die "incorrect username or passwd"; is not printing anything. That +s why i have written in the following #manner. if(! $ftp->login($user,$pass)) { print "incorrect user name or password"; die; } ################################## #put is working fine but get is not working $ftp->put($file); ################################### print $ftp->message; ##in the messege it is telling "ABORTED SUCCESSFULLY" print $c++," success"; $count--; }

thanks
MUNU

Edited by Chady -- added code tags.

Replies are listed 'Best First'.
Re: Problem with NET::FTP->GET functionality from the web
by tachyon (Chancellor) on Aug 09, 2004 at 15:03 UTC

    In vague order. DON'T SHOUT, ie use uppercase, we can read what you have to say just fine. You have been asked to do this before - please stop it You are using CGI.pm then running a hand parse routine??? %FORM = $q->Vars() and ditch the form parsing code. die and CGI does not give you an error in the browser. Try:

    use CGI::Carp 'fatalsToBrowser';

    Please read a tutorial or several. CGI Help Guide and Ovids web tutorial might be good places to start.

    The actual issue is probably related to the firewall, not perl but your explanation leaves a little to be desired. We don't want to see all your code. 10 lines that demonstrates the problem is all that is required. By the time you distill the problem down you have often solved it, if not you have a far better chance of getting it fixed.

    cheers

    tachyon

Re: Problem with NET::FTP->GET functionality from the web
by davorg (Chancellor) on Aug 09, 2004 at 14:59 UTC

    It's always worth adding "use strict" and "use warnings" to a program that you are have problems with. They will point out many things to fix in your code.

    You use the CGI module and create a CGI object ($q) but then you don't do any more with the object (other than printing the header). Instead you use a very nasty (and potentially buggy) CGI parameter parser.

    Fixing these issues will make it easier to track down the real problems with your code.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Problem with NET::FTP->GET functionality from the web
by gri6507 (Deacon) on Aug 09, 2004 at 16:58 UTC
    Just as a side thought, do you have permissions to GET the file into the folder you are operating from?
      Yes I have the required permission...